Click here to Skip to main content
15,902,189 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi friends

The following is my code in rowupdating event for getting dropdownlist value.

C#
string s = ((DropDownList)studacgrid.Rows[e.RowIndex].Cells[6].Controls[0]).SelectedValue;
            comp.SECTIONNAME = Convert.ToChar(s);


the error is

Unable to cast object of type 'System.Web.UI.LiteralControl' to type 'System.Web.UI.WebControls.DropDownList'.
Posted

Try this ...

C#
string s = ((DropDownList)studacgrid.Rows[e.RowIndex].FindControl("ComboBoxId")).SelectedValue;
comp.SECTIONNAME = Convert.ToChar(s);
 
Share this answer
 
C#
DropDownList yourDropDown = studacgrid.Rows[e.RowIndex].Cells[6].FindControl("yourDropDownID") as DropDownList;

string s = yourDropDown.SelectedValue;
comp.SECTIONNAME = Convert.ToChar(s);
 
Share this answer
 

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