前台:
<asp:GridView ID="grid" runat="server" class="com_table" AutoGenerateColumns="False">
<Columns>
<asp:TemplateField HeaderText="部门名称">
<ItemTemplate>
<asp:DropDownList ID="ddl_Dept" AutoPostBack="True" OnSelectedIndexChanged="ddl_Dept_SelectedIndexChanged" runat="server">
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
后台:
/// <summary>
/// 选择部门
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void ddl_Dept_SelectedIndexChanged(object sender, EventArgs e)
{
DropDownList drd = sender as DropDownList;
GridView gv = drd.Parent.Parent.Parent.Parent as GridView;
int n = ((GridViewRow)drd.Parent.Parent).RowIndex; //获取第多少行
var row = gv.Rows[n]; //获取当前行的rowData
}