在cs文件中怎么取页面上的GridView控件模板中用户控件里的DropDownList控件的值

--------------------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控件的值???


最好是让你的用户控件把你的下拉框的属性通过属性或方法的形式呈示出来,

譬如

public string SelectValue1
{
  get
  {
return DropDownList1.SelectedValue;
  }
}


否则的话,用(不推荐,因为这样就把你的用户控件和网页耦合起来了)

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;

posted on 2007-04-30 23:04  李冠甄  阅读(1163)  评论(0)    收藏  举报

导航