如何获得Datalist里面嵌套的DropDownList属性ID?求高手慷慨相助!!很急!在线等!

前台页面布局:

 <asp:datalist id="DataList1" runat="server" >
       <EditItemTemplate>
                    <tr>
            <td>
                   <asp:DropDownList ID="DropDownList0" runat="server" Font-Size="X-Small" Width="94px">
                    </asp:DropDownList>
             </td>
            </tr>
                </EditItemTemplate>
</asp:datalist>

后台C#:代码

public void ddlDataBind(string sqlstr, string dtf, string dvf)
    {
        SqlConnection sqlconn = new SqlConnection(System.Configuration.ConfigurationManager.AppSettings["sms_dbconn"].ToString());

        sqlconn.Open();
        SqlDataAdapter myda = new SqlDataAdapter(sqlstr, sqlconn);
        DataSet myds = new DataSet();
        myda.Fill(myds);
        if ((DropDownList)DataList1.FindControl("DropDownList0") != null) 
        {
            DropDownList ddl = (DropDownList)DataList1.FindControl("DropDownList0");
            ddl.DataSource = myds;
            ddl.DataTextField = dtf;
            ddl.DataValueField = dvf;
            ddl.DataBind();
        }

        sqlconn.Close();
    }

    如何获得Datalist里面嵌套的DropDownList属性ID?为DropDownList绑定数据?
    我用(DropDownList)DataList1.FindControl("DropDownList0")获取不到,请高手行家指点!!!

3个回答

后台添加个断点,看看DataList1中的内容,是否可以发现DropDownList。祝你好运!

my_00
my_00 我好像没找到
接近 5 年之前 回复
my_00
my_00 回复ligyu110: 很多内容:- DataList1 {System.Web.UI.WebControls.DataList} System.Web.UI.WebControls.DataList
接近 5 年之前 回复
ligyu110
老李家的小二 回复my_00: if ((DropDownList)DataList1.FindControl("DropDownList0") != null) 断点添加到此行,命中后,对DataList1右键“添加监视”,在监视框中查看
接近 5 年之前 回复
my_00
my_00 谢谢。在后台代码中输入DropDownList不显示DropDownList0
接近 5 年之前 回复

很多内容:是这样吗?

  • DataList1 {System.Web.UI.WebControls.DataList} System.Web.UI.WebControls.DataList
  • base {System.Web.UI.WebControls.DataList} System.Web.UI.WebControls.BaseDataList {System.Web.UI.WebControls.DataList}
  • base {System.Web.UI.WebControls.DataList} System.Web.UI.WebControls.WebControl {System.Web.UI.WebControls.DataList} Caption "" string CaptionAlign NotSet System.Web.UI.WebControls.TableCaptionAlign CellPadding 3 int CellSpacing 1 int
  • Controls {System.Web.UI.ControlCollection} System.Web.UI.ControlCollection DataKeyField "courseid" string
  • DataKeys {System.Web.UI.WebControls.DataKeyCollection} System.Web.UI.WebControls.DataKeyCollection DataMember "" string
  • DataSource {System.Data.DataSet} object {System.Data.DataSet} DataSourceID "" string GridLines None System.Web.UI.WebControls.GridLines HorizontalAlign NotSet System.Web.UI.WebControls.HorizontalAlign UseAccessibleHeader false bool
  • Static members
  • Non-Public members
  • [System.Web.UI.WebControls.DataList] {System.Web.UI.WebControls.DataList} System.Web.UI.WebControls.DataList
  • base {System.Web.UI.WebControls.DataList} System.Web.UI.WebControls.WebControl {System.Web.UI.WebControls.DataList}
  • _arguments {System.Web.UI.DataSourceSelectArguments} System.Web.UI.DataSourceSelectArguments
  • _currentView {System.Web.UI.WebControls.ReadOnlyDataSourceView} System.Web.UI.DataSourceView {System.Web.UI.WebControls.ReadOnlyDataSourceView} _currentViewIsFromDataSourceID false bool _currentViewValid true bool _inited true bool _pagePreLoadFired true bool _requiresDataBinding false bool _throwOnDataPropertyChange false bool
  • DataKeysArray Count = 1 System.Collections.ArrayList
  • dataKeysCollection {System.Web.UI.WebControls.DataKeyCollection} System.Web.UI.WebControls.DataKeyCollection
  • dataSource {System.Data.DataSet} object {System.Data.DataSet} Initialized true bool IsBoundUsingDataSourceID false bool RequiresDataBinding false bool
  • SelectArguments {System.Web.UI.DataSourceSelectArguments} System.Web.UI.DataSourceSelectArguments
  • AlternatingItemStyle {System.Web.UI.WebControls.TableItemStyle} System.Web.UI.WebControls.TableItemStyle AlternatingItemTemplate null System.Web.UI.ITemplate EditItemIndex 0 int
  • EditItemStyle {System.Web.UI.WebControls.TableItemStyle} System.Web.UI.WebControls.TableItemStyle
  • EditItemTemplate {System.Web.UI.CompiledTemplateBuilder} System.Web.UI.ITemplate {System.Web.UI.CompiledTemplateBuilder}
  • [System.Web.UI.CompiledTemplateBuilder] {System.Web.UI.CompiledTemplateBuilder} System.Web.UI.CompiledTemplateBuilder
  • Non-Public members
  • buildTemplateMethod {Method = {Void __BuildControl_control63(System.Web.UI.Control)}} System.Web.UI.BuildTemplateMethod
  • base {Method = {Void BuildControlcontrol63(System.Web.UI.Control)}} System.MulticastDelegate {System.Web.UI.BuildTemplateMethod}
  • base {Method = {Void BuildControlcontrol63(System.Web.UI.Control)}} System.Delegate {System.Web.UI.BuildTemplateMethod}
  • Method {Void BuildControlcontrol63(System.Web.UI.Control)} System.Reflection.MethodInfo {System.Reflection.RuntimeMethodInfo}
  • [System.Reflection.RuntimeMethodInfo] {Void BuildControlcontrol63(System.Web.UI.Control)} System.Reflection.RuntimeMethodInfo
  • base {Void BuildControlcontrol63(System.Web.UI.Control)} System.Reflection.MethodInfo {System.Reflection.RuntimeMethodInfo} Attributes Private | HideBySig System.Reflection.MethodAttributes CallingConvention Standard | HasThis System.Reflection.CallingConventions ContainsGenericParameters false bool
  • DeclaringType {Name = "course_aspx" FullName = "ASP.course_aspx"} System.Type {System.RuntimeType} IsGenericMethod false bool IsGenericMethodDefinition false bool MemberType Method System.Reflection.MemberTypes MetadataToken 100663486 int
  • MethodHandle {System.RuntimeMethodHandle} System.RuntimeMethodHandle
  • Module {App_Web_lnxplala.dll} System.Reflection.Module Name "__BuildControl__control63" string
  • ReflectedType {Name = "course_aspx" FullName = "ASP.course_aspx"} System.Type {System.RuntimeType}
  • ReturnParameter {Void } System.Reflection.ParameterInfo
  • ReturnType {Name = "Void" FullName = "System.Void"} System.Type {System.RuntimeType}
  • ReturnTypeCustomAttributes {Void } System.Reflection.ICustomAttributeProvider {System.Reflection.ParameterInfo}
  • Non-Public members
  • base {Void BuildControlcontrol63(System.Web.UI.Control)} System.Reflection.MethodInfo {System.Reflection.RuntimeMethodInfo} BindingFlags Instance | NonPublic System.Reflection.BindingFlags IsOverloaded false bool m_bindingFlags Instance | NonPublic System.Reflection.BindingFlags
  • m_declaringType {Name = "course_aspx" FullName = "ASP.course_aspx"} System.RuntimeType
  • m_handle {System.RuntimeMethodHandle} System.RuntimeMethodHandle m_invocationFlags 0 uint m_methodAttributes Private | HideBySig System.Reflection.MethodAttributes m_name "__BuildControl__control63" string
  • m_parameters {System.Reflection.ParameterInfo[1]} System.Reflection.ParameterInfo[]
  • m_reflectedTypeCache {System.RuntimeType.RuntimeTypeCache} System.RuntimeType.RuntimeTypeCache
  • m_returnParameter {Void } System.Reflection.ParameterInfo
  • m_signature {System.Signature} System.Signature m_toString "Void BuildControlcontrol63(System.Web.UI.Control)" string
  • ReflectedTypeHandle {System.RuntimeTypeHandle} System.RuntimeTypeHandle
  • Signature {System.Signature} System.Signature
  • base {Void BuildControlcontrol63(System.Web.UI.Control)} System.Reflection.MethodBase {System.Reflection.RuntimeMethodInfo} ContainsGenericParameters false bool IsGenericMethod false bool IsGenericMethodDefinition false bool MemberType Method System.Reflection.MemberTypes
  • ReturnParameter {Void } System.Reflection.ParameterInfo
  • ReturnType {Name = "Void" FullName = "System.Void"} System.Type {System.RuntimeType}
  • [System.RuntimeType] {Name = "Void" FullName = "System.Void"} System.RuntimeType
  • base {Name = "Void" FullName = "System.Void"} System.Reflection.MemberInfo {System.RuntimeType}
  • Assembly {mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089} System.Reflection.Assembly AssemblyQualifiedName "System.Void, mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" string Attributes Public | SequentialLayout | Sealed | Serializable | BeforeFieldInit System.Reflection.TypeAttributes
  • BaseType {Name = "ValueType" FullName = "System.ValueType"} System.Type {System.RuntimeType} ContainsGenericParameters false bool
  • DeclaringMethod '((((System.Delegate)(((System.Web.UI.CompiledTemplateBuilder)(DataList1.EditItemTemplate))._buildTemplateMethod)).Method).ReturnType).DeclaringMethod' threw an exception of type 'System.InvalidOperationException' System.Reflection.MethodBase {System.InvalidOperationException}
  • DeclaringType null System.Type FullName "System.Void" string
  • GenericParameterAttributes '((((System.Delegate)(((System.Web.UI.CompiledTemplateBuilder)(DataList1.EditItemTemplate))._buildTemplateMethod)).Method).ReturnType).GenericParameterAttributes' threw an exception of type 'System.InvalidOperationException' System.Reflection.GenericParameterAttributes {System.InvalidOperationException}
  • GenericParameterPosition '((((System.Delegate)(((System.Web.UI.CompiledTemplateBuilder)(DataList1.EditItemTemplate))._buildTemplateMethod)).Method).ReturnType).GenericParameterPosition' threw an exception of type 'System.InvalidOperationException' int {System.InvalidOperationException}
  • GUID {ca5c1c2b-61f8-3fc4-b66b-17163a3066a5} System.Guid HasElementType false bool IsAbstract false bool IsAnsiClass true bool IsArray false bool IsAutoClass false bool IsAutoLayout false bool IsByRef false bool IsClass false bool IsCOMObject false bool IsContextful false bool IsEnum false bool IsExplicitLayout false bool IsGenericParameter false bool IsGenericType false bool IsGenericTypeDefinition false bool IsImport false bool IsInterface false bool IsLayoutSequential true bool IsMarshalByRef false bool IsNested false bool IsNestedAssembly false bool IsNestedFamANDAssem false bool IsNestedFamily false bool IsNestedFamORAssem false bool IsNestedPrivate false bool IsNestedPublic false bool IsNotPublic false bool IsPointer false bool IsPrimitive false bool IsPublic true bool IsSealed true bool IsSerializable true bool IsSpecialName false bool IsUnicodeClass false bool IsValueType true bool IsVisible true bool MemberType TypeInfo System.Reflection.MemberTypes
  • Module {CommonLanguageRuntimeLibrary} System.Reflection.Module Namespace "System" string
  • ReflectedType null System.Type
  • StructLayoutAttribute {System.Runtime.InteropServices.StructLayoutAttribute} System.Runtime.InteropServices.StructLayoutAttribute
  • TypeHandle {System.RuntimeTypeHandle} System.RuntimeTypeHandle
  • TypeInitializer null System.Reflection.ConstructorInfo
  • UnderlyingSystemType {Name = "Void" FullName = "System.Void"} System.Type {System.RuntimeType}
  • Static members
  • Non-Public members
  • ReturnTypeCustomAttributes {Void } System.Reflection.ICustomAttributeProvider {System.Reflection.ParameterInfo}
  • [System.Reflection.ParameterInfo] {Void } System.Reflection.ParameterInfo
  • Target {ASP.course_aspx} object {ASP.course_aspx}
  • base {ASP.course_aspx} course {ASP.course_aspx}
  • Static members
  • Non-Public members
  • [System.Web.UI.BuildTemplateMethod] {Method = {Void BuildControlcontrol63(System.Web.UI.Control)}} System.Web.UI.BuildTemplateMethod
  • methodBase {Void __BuildControl_control63(System.Web.UI.Control)} System.Reflection.MethodBase {System.Reflection.RuntimeMethodInfo}
  • _methodPtr 45217496 System.IntPtr
  • _methodPtrAux 0 System.IntPtr
  • _target {ASP.course_aspx} object {ASP.course_aspx}
  • Non-Public members
  • [System.Web.UI.BuildTemplateMethod] {Method = {Void BuildControlcontrol63(System.Web.UI.Control)}} System.Web.UI.BuildTemplateMethod
  • base {Method = {Void BuildControlcontrol63(System.Web.UI.Control)}} System.Delegate {System.Web.UI.BuildTemplateMethod}
  • _invocationCount 0 System.IntPtr _invocationList null object ExtractTemplateRows false bool
  • FooterStyle {System.Web.UI.WebControls.TableItemStyle} System.Web.UI.WebControls.TableItemStyle FooterTemplate null System.Web.UI.ITemplate GridLines None System.Web.UI.WebControls.GridLines
  • HeaderStyle {System.Web.UI.WebControls.TableItemStyle} System.Web.UI.WebControls.TableItemStyle HeaderTemplate null System.Web.UI.ITemplate
  • Items {System.Web.UI.WebControls.DataListItemCollection} System.Web.UI.WebControls.DataListItemCollection
  • ItemStyle {System.Web.UI.WebControls.TableItemStyle} System.Web.UI.WebControls.TableItemStyle
  • ItemTemplate {System.Web.UI.CompiledTemplateBuilder} System.Web.UI.ITemplate {System.Web.UI.CompiledTemplateBuilder} RepeatColumns 0 int RepeatDirection Vertical System.Web.UI.WebControls.RepeatDirection RepeatLayout Table System.Web.UI.WebControls.RepeatLayout SelectedIndex -1 int SelectedItem null System.Web.UI.WebControls.DataListItem
  • SelectedItemStyle {System.Web.UI.WebControls.TableItemStyle} System.Web.UI.WebControls.TableItemStyle SelectedItemTemplate null System.Web.UI.ITemplate SelectedValue null object
  • SeparatorStyle {System.Web.UI.WebControls.TableItemStyle} System.Web.UI.WebControls.TableItemStyle SeparatorTemplate null System.Web.UI.ITemplate ShowFooter true bool ShowHeader true bool
  • Static members
  • Non-Public members
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问