How to get text of dropdownlist of gridview
I have a gridview, in which i have taken dropdown explicitely and added 10 values in it. how can i get selected text of drop down when i change it runtime. selected index change is not giving output.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Raja KrishnamurthyRank #3,615 · 403 reputationPosted Mar 7, 2011, 2:43 AM EST
http://stackoverflow.com/questions/485390/why-isnt-the-selectedindexchanged-event-firing-from-a-dropdownlist-in-a-gridview
HTH.
Happy Programming!!!
Regards,
Raja
Krishna GaradRank #191 · 12.8K reputationPosted Mar 7, 2011, 12:14 AM EST
DropDownList ddltemp=new DropDownList();
foreach(GridViewRow row in Gridview1.Rows)
{
ddltemp=(DropDownList)row.FindControl("Idofddl");
string _text=ddltemp.SelectedItem.Text.ToString();
}
}
Suthish NairRank #92 · 22.8K reputationPosted Mar 7, 2011, 1:24 AM EST
On GV1_SelectedIndexChanged
DropDownList tmpdll = (DropDownList) GV1.Rows[GV1.SelectedIndex].Cells[1].FindControl("ddl");
String val = tmpdll.SelectedItem.Text;
tmpdll = null;
Suthish NairRank #92 · 22.8K reputationPosted Mar 7, 2011, 9:51 AM EST
Mayur Gujrathi85 reputationPosted Mar 7, 2011, 8:28 PM EST
Answer you have given is right but it is giving text of every dropdownlist but i have 10 dropdown as 10 there 10 rows in gridview, correct answer is in post itself given by raja.krish
Mayur Gujrathi85 reputationPosted Mar 7, 2011, 8:30 PM EST
Mayur Gujrathi85 reputationPosted Mar 8, 2011, 4:41 AM EST
I have tried like this
string sample=Grid1.Rows[e.Rowindex].cells[0].Tostring
e.rowindex is not coming in intellence and problem is not getting to pick row no on for which drop down is selected
Mayur Gujrathi85 reputationPosted Mar 8, 2011, 4:41 AM EST
I have tried like this
string sample=Grid1.Rows[e.Rowindex].cells[0].Tostring
e.rowindex is not coming in intellence and problem is not getting to pick row no on for which drop down is selected
Mayur Gujrathi85 reputationPosted Mar 8, 2011, 4:42 AM EST
but i have another problem , now i am getting text of dropdown but as there are 5 columns i want text of every field of that row in which drop down is selected
I have tried like this
string sample=Grid1.Rows[e.Rowindex].cells[0].Tostring
e.rowindex is not coming in intellence and problem is not getting to pick row no on for which drop down is selected
Mayur Gujrathi85 reputationPosted Mar 8, 2011, 4:42 AM EST
but i have another problem , now i am getting text of dropdown but as there are 5 columns i want text of every field of that row in which drop down is selected
I have tried like this
string sample=Grid1.Rows[e.Rowindex].cells[0].Tostring
e.rowindex is not coming in intellence and problem is not getting to pick row no on for which drop down is selected
Raja KrishnamurthyRank #3,615 · 403 reputationPosted Mar 8, 2011, 7:29 AM EST
in the dropdownlist selected index changed method. try this:
GridViewRow objRow = (GridViewRow)((DropDownList)Sender).Parent.Parent; //this should get you the GridViewRow (first parent will get you the column)
Now that you have the GridViewRow you can do select the columns and so on and so forth. Again I cannot assure you results but it might be worth trying.
HTH.
Happy Programming!!!
Regards,
Raja