GV里的Dropdownlist的postback事件写在哪里?
前台页里的GV里的模版列里有一个dropdownlist
<asp:DropDownList runat= "server " ID= "WL " AutoPostBack= "true ">
设置了自动回发.
但这是在一个GV里面.应该写在哪个事件中???
应该怎么得到dropdownlist的参数并进行操作???
------解决方案--------------------直接使用页级事件处理程序
// .aspx
<asp:TemplateField>
<ItemTemplate>
<asp:DropDownList ID= "DropDownList1 " runat= "server " OnSelectedIndexChanged= "DropDownList1_SelectedIndexChanged ">
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
// .aspx.cs
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
DropDownList drp = sender as DropDownList; // 触发事件的 DDL
string val = drp.SelectedValue;
GridViewRow row = drp.NamingContainer as GridViewRow; // GridView 中对应的行
int id = (int)GridView1.DataKeys[row.RowIndex].Value;
// ...
}