Click here to Skip to main content
16,021,293 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello
I am not able to genrate selectedItem Event for Dropdown list in edittemplate in RowUpdate() nor in RowCommand()

C#
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();

}
Posted
Updated 26-Sep-12 23:36pm
v3
Comments
Anele Ngqandu 27-Sep-12 5:04am    
What errors you get and if you have any code please post it.
Malli_S 27-Sep-12 5:10am    
If possible show up some code snippet, that would help to figure out the error.
Meenakshi Moolani 27-Sep-12 5:34am    
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();

}

In RowUpdating Event Of the grid

write this code it will get the dropdownlist Selected Item

C#
(GridView1.Rows[e.RowIndex].FindControl("DropDownListName") as DropDownList).SelectedItem ;


Regards,
Ahmed Mandour
 
Share this answer
 
Comments
Meenakshi Moolani 27-Sep-12 5:27am    
i have used but its selecting onlt 0th item "select" even on changing index
Check whether you've set 'AutoPostBack' property of dropdown list to 'True' and 'SelectedIndexChanged ' event is handled.
 
Share this answer
 
Comments
Meenakshi Moolani 27-Sep-12 5:30am    
its true and how can i handle it in RowUpdate event of GridView as dropdown in edit template of GridView
Malli_S 27-Sep-12 5:45am    
Do you have any duplicate values in the dropdownlist?
You can check this article http://www.codeproject.com/Articles/53559/Accessing-a-DropDownList-inside-a-GridView.
Meenakshi Moolani 27-Sep-12 6:46am    
No i dont have duplicate values in them
Malli_S 27-Sep-12 7:17am    
Hey try using

e.Item.FindControl()

instead of

GridViewDepartment.Rows[e.RowIndex].FindControl()
Meenakshi Moolani 27-Sep-12 8:19am    
i used bt not working in row update event
[Edit:- Moved text to question.]
 
Share this answer
 
v4
Comments
Meenakshi Moolani 27-Sep-12 5:37am    
sorry i have got you
Malli_S 27-Sep-12 5:47am    
??

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900