无法为gridView中的下拉列表生成事件 [英] Unable to Genrate an event for DropDown list in gridView
本文介绍了无法为gridView中的下拉列表生成事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你好
我无法在RowUpdate()或RowCommand()中的edittemplate中生成下拉列表的selectedItem事件
Hello
I am not able to genrate selectedItem Event for Dropdown list in edittemplate in RowUpdate() nor in RowCommand()
protected void GridViewDepartment_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
getConnection = connection.SetConnection();
GridView GridViewDepartment = (GridView)sender;
GridViewDepartment.EditIndex = e.RowIndex;
GridViewDepartment.DataSource = departmentTable;
GridViewDepartment.DataBind();
int DepartmentID = (int)GridViewDepartment.DataKeys[e.RowIndex].Value;
DropDownList ddlManager = ((DropDownList)GridViewDepartment.Rows[e.RowIndex].FindControl("ddlDepartManager"));
string AssignNewManagr = ddlManager.SelectedItem.Text.ToString(); // this selecting only "select" 0th item only even on changing index
string AssignNewActive = ((DropDownList)GridViewDepartment.Rows[e.RowIndex].FindControl("DropDownListActive")).SelectedItem.ToString();
string SPUPDateDepartment = "SPModifyDepartment";
SqlCommand UPDateCommnad = new SqlCommand(SPUPDateDepartment, getConnection);
UPDateCommnad.CommandType = CommandType.StoredProcedure;
UPDateCommnad.Parameters.AddWithValue("@DepartmentId", DepartmentID);
UPDateCommnad.Parameters.AddWithValue("@DepartmentManager", AssignNewManagr);
UPDateCommnad.Parameters.AddWithValue("@Active", AssignNewActive);
UPDateCommnad.ExecuteNonQuery();
GridViewDepartment.EditIndex = -1;
GetDepartmentList();
}
推荐答案
在网格的RowUpdating事件中
编写此代码,它将获得下拉列表Selected Item
In RowUpdating Event Of the grid
write this code it will get the dropdownlist Selected Item
(GridView1.Rows[e.RowIndex].FindControl("DropDownListName") as DropDownList).SelectedItem ;
问候,
艾哈迈德·曼杜尔(Ahmed Mandour)
Regards,
Ahmed Mandour
检查是否已将下拉列表的"AutoPostBack"属性设置为"True",并且是否处理了"SelectedIndexChanged"事件.
Check whether you''ve set ''AutoPostBack'' property of dropdown list to ''True'' and ''SelectedIndexChanged '' event is handled.
这篇关于无法为gridView中的下拉列表生成事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文