------------------ DDList. ascx -----------------
<Asp: DropDownList ID = "DropDownList1" runat = "server" AutoPostBack = "True" DataSourceID = "SqlDataSource1"
DataTextField = "lbname" DataValueField = "lbid" OnSelectedIndexChanged = "DropDownList1_SelectedIndexChanged">
</Asp: DropDownList>
<Atlas: UpdatePanel ID = "UpdatePanel1" runat = "server">
<ContentTemplate>
<Asp: DropDownList ID = "DropDownList2" runat = "server">
</Asp: DropDownList>
</ContentTemplate>
<Triggers>
<Atlas: ControlEventTrigger ControlID = "DropDownList1" EventName = "SelectedIndexChanged"/>
</Triggers>
</Atlas: UpdatePanel>
--------------------------------------- Index. aspx ----------------------------------------
<Asp: GridView ID = "GridView1" runat = "server" AutoGenerateColumns = "False" performanceid = "sqlperformance1">
<Columns>
<Asp: TemplateField HeaderText = "category">
<EditItemTemplate>
<Asp: TextBox ID = "TextBox1" runat = "server"> </asp: TextBox>
</Edititemtemplate>
<Itemtemplate>
<Uc1: ddlist id = "ddlist1" runat = "server"/>
</Itemtemplate>
</ASP: templatefield>
</Columns>
</ASP: gridview>
--------------------------------------- Index. aspx. cs ------------
In the cs file, how do I obtain the values of the DropDownList1 and DropDownList2 controls of the DDList1 user control ???
It is best for your user control to display the attributes of your drop-down box in the form of attributes or methods,
For example
Public string SelectValue1
{
Get
{
Return DropDownList1.SelectedValue;
}
}
Otherwise, it will be used (not recommended, because it will coupling your user control with the webpage)
DropDownList ddl = GridView1.Rows [n]. FindControl ("DDList1"). FindControl ("DropDownList1") as DropDownList;
Public class DDList: userControl
{
Public string SelectValue1
{
Get
{
Return DropDownList1.SelectedValue;
}
}
....
}
DDList d = GridView1.Rows [n]. FindControl ("DDList1") as DDList;
String s = d. SelectedValue1;