Using DrowDownlist in GridView

J

jack

Hi im trying to use DrowDownList in the Gridview control for the first
time and have just a little idea about how it works
i have tried some code from the net but was able to find the code of
DataGrid with DropDownList. But displays some error when i click on the
edit button


Im trying to use Dropdownlist in the gridview. but in the RowEditing
event The error is thrown here
protected void GridView1_RowEditing(object sender,
GridViewEditEventArgs e)
{
Response.Write("Value changed to ");

System.Web.UI.WebControls.Label lb = new
System.Web.UI.WebControls.Label();
DropDownList ddl = (DropDownList)
GridView1.SelectedRow.FindControl("ddl_UnitCode");
(Error is thrown here : Object reference not set to an instance of an
object.)
BindGrid();
}


the error occurs when i click on edit buttton..
 
G

Gaurav Vaish \(MasterGaurav\)

Im trying to use Dropdownlist in the gridview. but in the RowEditing
event The error is thrown here
System.Web.UI.WebControls.Label lb = new
System.Web.UI.WebControls.Label();
DropDownList ddl = (DropDownList)
GridView1.SelectedRow.FindControl("ddl_UnitCode");
(Error is thrown here : Object reference not set to an instance of an
object.)


No row is selected.
You are in edit mode... work with EditIndex.

DropDownList ddl = (DropDownList)
GridView1.Rows[e.NewEditIndex].FindControl("dll_UnitCode");

where e is GridViewEditEventArgs (parameter to the handler).


--
Happy Hacking,
Gaurav Vaish | www.mastergaurav.com
www.edujini-labs.com
http://eduzine.edujinionline.com
-----------------------------------------
 
G

Gaurav Vaish \(MasterGaurav\)

Im trying to use Dropdownlist in the gridview. but in the RowEditing
event The error is thrown here
System.Web.UI.WebControls.Label lb = new
System.Web.UI.WebControls.Label();
DropDownList ddl = (DropDownList)
GridView1.SelectedRow.FindControl("ddl_UnitCode");
(Error is thrown here : Object reference not set to an instance of an
object.)


No row is selected.
You are in edit mode... work with EditIndex.

DropDownList ddl = (DropDownList)
GridView1.Rows[e.NewEditIndex].FindControl("dll_UnitCode");

where e is GridViewEditEventArgs (parameter to the handler).


--
Happy Hacking,
Gaurav Vaish | www.mastergaurav.com
www.edujini-labs.com
http://eduzine.edujinionline.com
-----------------------------------------
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top