By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,277 Members | 1,200 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,277 IT Pros & Developers. It's quick & easy.

DropDownList in DataGrid EditMode

P: n/a
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.

Nov 17 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
You have to create the control to which you are binding.
Like 'list' in your case.
"Islam Elkhayat" <Is******@SaveMyPrivacy.com> wrote in message
news:ui**************@TK2MSFTNGP10.phx.gbl...
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.

Nov 17 '05 #2

P: n/a
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

Nov 17 '05 #3

P: n/a
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
"Vaibhav" <co************@yahoo.com> wrote in message
news:ex**************@TK2MSFTNGP14.phx.gbl...
You have to create the control to which you are binding.
Like 'list' in your case.
"Islam Elkhayat" <Is******@SaveMyPrivacy.com> wrote in message
news:ui**************@TK2MSFTNGP10.phx.gbl...
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.


Nov 17 '05 #4

P: n/a
are you sure you have the ONITEMDATABOUND="Datagrrd1_ItemDataBound" set in
the html? your code is all fine.

"Islam Elkhayat" wrote:
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.

Nov 17 '05 #5

P: n/a
are you sure you have the ONITEMDATABOUND="Datagrrd1_ItemDataBound" set in
the html? your code is all fine.

"Islam Elkhayat" wrote:
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.

Nov 17 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.