469,924 Members | 1,365 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,924 developers. It's quick & easy.

DropDownList template column in DataGrid

mg
I have a DataGrid (WebForm - C#) that has a template column that contains a dropdownlist named "DdlTest"

In DataGrid1_UpdateCommand, the lin

DropDownList ddlTest = (DropDownList) e.Item.FindControl("DdlTest")

enables me to work with ddlTest - with, for example, ddlTest.SelectedValu

However, in DataGrid1_EditCommand, ddlTest.SelectedValue returns "Object reference not set to an instance of an object.

Is it possible to work with DdlTest in DataGrid1_EditCommand?
Nov 18 '05 #1
3 6022
mg
My goal is to have a dropdownlist in the template column of a datagrid come up with the last saved value selected, when the user clicks 'edit'
Nov 18 '05 #2
jm
if e.item.ItemType = ListItemType.EditItem then
.....
"mg" <mg@theworld.com> wrote in message
news:F0**********************************@microsof t.com...
I have a DataGrid (WebForm - C#) that has a template column that contains a dropdownlist named "DdlTest" :
In DataGrid1_UpdateCommand, the line

DropDownList ddlTest = (DropDownList) e.Item.FindControl("DdlTest");

enables me to work with ddlTest - with, for example, ddlTest.SelectedValue

However, in DataGrid1_EditCommand, ddlTest.SelectedValue returns "Object reference not set to an instance of an object."
Is it possible to work with DdlTest in DataGrid1_EditCommand? if e.item.ItemType = ListItemType.EditItem then
.....
"mg" <mg@theworld.com> wrote in message
news:F0**********************************@microsof t.com... I have a DataGrid (WebForm - C#) that has a template column that contains a dropdownlist named "DdlTest" :
In DataGrid1_UpdateCommand, the line

DropDownList ddlTest = (DropDownList) e.Item.FindControl("DdlTest");

enables me to work with ddlTest - with, for example, ddlTest.SelectedValue

However, in DataGrid1_EditCommand, ddlTest.SelectedValue returns "Object reference not set to an instance of an object."
Is it possible to work with DdlTest in DataGrid1_EditCommand?

Nov 18 '05 #3
jm
"jm" <jo*************@yahoo.com> wrote in message news:<13upc.55387$iF6.4990864@attbi_s02>...
if e.item.ItemType = ListItemType.EditItem then
....
"mg" <mg@theworld.com> wrote in message
news:F0**********************************@microsof t.com...
I have a DataGrid (WebForm - C#) that has a template column that contains

a dropdownlist named "DdlTest" :

In DataGrid1_UpdateCommand, the line

DropDownList ddlTest = (DropDownList) e.Item.FindControl("DdlTest");

enables me to work with ddlTest - with, for example, ddlTest.SelectedValue

However, in DataGrid1_EditCommand, ddlTest.SelectedValue returns "Object

reference not set to an instance of an object."

Is it possible to work with DdlTest in DataGrid1_EditCommand?

if e.item.ItemType = ListItemType.EditItem then
....
"mg" <mg@theworld.com> wrote in message
news:F0**********************************@microsof t.com...
I have a DataGrid (WebForm - C#) that has a template column that contains

a dropdownlist named "DdlTest" :

In DataGrid1_UpdateCommand, the line

DropDownList ddlTest = (DropDownList) e.Item.FindControl("DdlTest");

enables me to work with ddlTest - with, for example, ddlTest.SelectedValue

However, in DataGrid1_EditCommand, ddlTest.SelectedValue returns "Object

reference not set to an instance of an object."

Is it possible to work with DdlTest in DataGrid1_EditCommand?

mg,

I found another way also:

http://www.aspnet101.com/aspnet101/p...ials.aspx?id=4

"Selecting Exact Items
To select a particular item in the list, based on the text (visible)
item, you can use this code:

DropDownList.SelectedIndex =
DropDownList.Items.IndexOf(DropDownList.Items.Find ByText("text"))

To select a particular item in the list, based on the Value of the
item, use this code:

DropDownList.SelectedIndex =
DropDownList.Items.IndexOf(DropDownList.Items.Find ByValue("value"))

Code for a ListBox is a little simpler:

ListBox.Items.FindByText("Text").Selected = true
ListBox.Items.FindByValue("value").Selected = true"
These should be very helpful to you.
Nov 18 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by sunstarwu | last post: by
5 posts views Thread by Islam Elkhayat | last post: by
1 post views Thread by Balaji | last post: by
3 posts views Thread by Richard | last post: by
reply views Thread by Daniel Doyle | last post: by
4 posts views Thread by TheHach | last post: by
reply views Thread by samuelberthelot | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.