Click here to Skip to main content
15,895,011 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
i'm having a gridview in which it has 10 columns and one of which is a dropdown i wanna take the selected value from it and save in a specific column of a database i wanna know how and where to access this dropdownlist. if there is a code it will be useful plzzz help
Posted

1 solution

its simple, please follow the below code
C#
DropDownList lstuserName = (DropDownList)gvRow.FindControl("ddl_groub");
  Response.Write("Selected Value : " + lstuserName.SelectedValue + " " + "Selected Item : " + lstuserName.SelectedItem.Text);
 
Share this answer
 
Comments
Member 11698441 21-May-15 0:20am    
Thanks, May i know the function where this C# code to be added?
Arun Kumar_Tech 21-May-15 0:36am    
Based on your requirement you have to use that code inside the function, if you say your requirement means i will try to explain it.
Member 11698441 21-May-15 0:42am    
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
Label lblupdateid = (Label)GridView2.Rows[e.RowIndex].FindControl("slnoLabel");
DropDownList drp = (DropDownList)sender;
GridViewRow gv = (GridViewRow)drp.NamingContainer;
DropDownList lstuserName = (DropDownList)gv.FindControl("DropDownList1");
Response.Write("Selected Value : " + lstuserName.SelectedValue + " " + "Selected Item : " + lstuserName.SelectedItem.Text);
string query = "update leaveforum set status1=" + lstuserName.SelectedItem.Text where SL_No =" + lblupdateid.Text;
GridView2.EditIndex = -1;
conn.Open();
SqlCommand cmd = new SqlCommand(query, conn);
cmd.ExecuteNonQuery();
conn.Close();
gvbind1();
}
this is drop down table should i give like this but its throwing errror at e.RowIndex and it couldnt seperate as string query = "update leaveforum set status1=" + lstuserName.SelectedItem.Text where SL_No =" + lblupdateid.Text;
Member 11698441 21-May-15 0:49am    
my requirement is like its a leave forum and its entered into db by one user and another user accepts it so a drop down is placed in grid now i want this selected text from dropdown to be posted in the db
Arun Kumar_Tech 21-May-15 0:51am    
DropDownList1 is not inside gridview right, then Eventargs e deals with event reards to DropDownList1, how can you use e.rowindex, your code seems wrong.

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