DropDownList in DataGrid EditMode

  • Thread starter Thread starter Islam Elkhayat
  • Start date Start date
I

Islam Elkhayat

In my webproject i have a datagrid.. i added a DropDownList in the edit mde
and in the Datagrrd1_ItemDataBound i bind data from dataview using:

if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==
ListItemType.AlternatingItem)
DropDownList list = (DropDownList)Datagrid1.FindControl("myddl");
list.DataSource = dv;
list.DataTextFeild= "Name";
list.DataValueFeild = "ID";
list.DataBind();

but i got and "object refrence not set to an instance of an object"
Exception..
it seem it's try to bind data b4 creating the DropDownlist itself!!

i add another Dropdownlist outside the grid which use the same Datasource
and it's wrk perfectly.
 
You have to create the control to which you are binding.
Like 'list' in your case.
 
is this a web user control you're developing? i vaguely recall a call
that I've had to make in the past, under similar circumstances, to
assert that the control has been created. sorry I can't remember off
hand
 
sure i did add a dropdownlist control to a Template column in the edit item
template..
is there a way to fix the error?
thanx
 
are you sure you have the ONITEMDATABOUND="Datagrrd1_ItemDataBound" set in
the html? your code is all fine.
 

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

Back
Top