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

DropDownList template column in DataGrid

P: n/a
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
Share this Question
Share on Google+
3 Replies


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

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

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