In the cs file, how does one obtain the value of the DropDownList control in the user control in the page's GridView control template?

Source: Internet
Author: User

------------------ 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;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.