--------------------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" DataSourceID="SqlDataSource1">
<Columns>
<asp:TemplateField HeaderText="分类">
<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 ------------在cs文件里怎么取DDList1用户控件的DropDownList1和DropDownList2控件的值???
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" DataSourceID="SqlDataSource1">
<Columns>
<asp:TemplateField HeaderText="分类">
<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 ------------在cs文件里怎么取DDList1用户控件的DropDownList1和DropDownList2控件的值???
{
get
{
return DropDownList1.SelectedValue;
}
}
否则的话,用(不推荐,因为这样就把你的用户控件和网页耦合起来了)DropDownList ddl = GridView1.Rows[n].FindControl("DDList1").FindControl("DropDownList1") as DropDownList;
{
get
{
return DropDownList1.SelectedValue;
}
}
这种方法怎么取值??
===>把它作为用户控件的public 属性.
public class DDList : userControl
{
public string SelectValue1
{
get
{
return DropDownList1.SelectedValue;
}
}
....}DDList d = GridView1.Rows[n].FindControl("DDList1") as DDList;
string s = d.SelectedValue1;