两个DropDownList在DataGrid里,后一个随着前一个改变而改变
前台代码如下:
<asp:DataGrid ID="DataGrid1" runat="server" AllowPaging="True" AutoGenerateColumns="False"
Width="100%" CssClass="colortable">
<FooterStyle CssClass="Table_Foot" />
<EditItemStyle CssClass="Table_Edit" />
<SelectedItemStyle CssClass="Table_Select" />
<PagerStyle CssClass="Table_Page" HorizontalAlign="Center" Visible="False" />
<AlternatingItemStyle CssClass="in3" />
<ItemStyle CssClass="in2" />
<HeaderStyle CssClass="listtop" />
<Columns>
<asp:TemplateColumn HeaderText="目标舍" ItemStyle-CssClass="checkwidth" HeaderStyle-Width="50">
<ItemTemplate>
<asp:DropDownList runat="server" ID="DropDownListHouseID" OnSelectedIndexChanged="DropDownListHouseID_SelectedIndexChanged"
AutoPostBack="true">
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="目标栏" ItemStyle-CssClass="checkwidth" HeaderStyle-Width="50">
<ItemTemplate>
<asp:DropDownList runat="server" ID="DropDownListHurdle">
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:DataGrid>
后台代码如下:
protected void DropDownListHouseID_SelectedIndexChanged(object sender, EventArgs e)
{
DropDownList dpl = sender as DropDownList;
object obj = dpl.NamingContainer;
DataGridItem di = (DataGridItem)dpl.NamingContainer;
DropDownList dplhurdle = (DropDownList)di.Cells[10].FindControl("DropDownListHurdle");
dplhurdle.DataSource = 数据集
dplhurdle.DataTextField = ;
dplhurdle.DataValueField = ;
dplhurdle.DataBind();
}