在GridView的中有一個DropDownList,并且DropDownList有回傳事件
最近做一個項目,需要在GridView中的ItemTemplate中添加一個DropDownList,并且當我選擇這個DropDownList得時候,他需要向服務器回傳數據:
如下圖:
一開始想在GridView中的<RowDataBound>事件中寫呢,可是DropDownList又沒有CommandName屬性
所以只有在DropDownList得SelecedIndexChanged事件中寫了,具體步驟:
在GridView得編輯狀態下,雙擊DropDownList就會進入到下面的事件中,代碼如下:
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
DropDownList Type = sender as DropDownList;
TableCell cell = (TableCell)Type.Parent;
GridViewRow item = (GridViewRow)cell.Parent;
string sql = "Update t_MemberInfo set YX=" + Type.SelectedValue+" and where Id="+item.Cells[0].Text;
dal.RunSql(sql);
gridViewBind(); / /GridView綁定事件
}
浙公網安備 33010602011771號