my_00
my_00
2015-05-12 02:25

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

  • dropdownlist
  • datalist
  • 获取 属性

前台页面布局:

 <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条回答