473,407 Members | 2,306 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

Drop Down List inside a Datagrid

Good Morning,
Quick question, I have an EditItemTemplate inside a datagrid. It should
contain a drop down list of possible choices. I have an EditCommandColumn.
The drop dow list column should initially contain the value of the field.
This works fine with
<ItemTemplate><%# Container.DataItem("NameType")%></ItemTemplate>

The desired effect is for the drop down list to databind to a query to show
possible choices when the user clicks the edit link. I can not get a
reference to the drop down list when the user clicks edit. Does anyone know
how to do this?

I tried page.findcontrol("controlname") and it does not work. Any ideas? I
get a NullReference Error when I do this, because I guess the control does
not exist on the page.

Thanks to everyone,
Chris
Nov 19 '05 #1
4 1461
Within the method that handles the datagrid EditCommand event you can get a
reference to the dropdown list by using the passed DataGridCommandEventArgs
as follows:
CType(e.Item.FindControl("controlname"), DropDownList)
--
http://www.webswapp.com
http://www.societopia.net
"Chris Kettenbach" wrote:
Good Morning,
Quick question, I have an EditItemTemplate inside a datagrid. It should
contain a drop down list of possible choices. I have an EditCommandColumn.
The drop dow list column should initially contain the value of the field.
This works fine with
<ItemTemplate><%# Container.DataItem("NameType")%></ItemTemplate>

The desired effect is for the drop down list to databind to a query to show
possible choices when the user clicks the edit link. I can not get a
reference to the drop down list when the user clicks edit. Does anyone know
how to do this?

I tried page.findcontrol("controlname") and it does not work. Any ideas? I
get a NullReference Error when I do this, because I guess the control does
not exist on the page.

Thanks to everyone,
Chris

Nov 19 '05 #2
No, that still didn't work. Any other suggestions?
I ended up with this

Sub DataGrid_Edit(ByVal Sender As Object, ByVal E As
DataGridCommandEventArgs)

' turn on editing for the selected row

Dim ddl As DropDownList = CType(E.Item.FindControl("drpNameType"),
DropDownList)

If Not isEdit Then

dg1.EditItemIndex = E.Item.ItemIndex

BindGrid()

End If
End Sub

Using a breakpoint, I see ddl = Nothing. What am I doing wrong here? Thanks!

"Phillip Williams" <Ph**************@webswapp.com> wrote in message
news:B6**********************************@microsof t.com...
Within the method that handles the datagrid EditCommand event you can get
a
reference to the dropdown list by using the passed
DataGridCommandEventArgs
as follows:
CType(e.Item.FindControl("controlname"), DropDownList)
--
http://www.webswapp.com
http://www.societopia.net
"Chris Kettenbach" wrote:
Good Morning,
Quick question, I have an EditItemTemplate inside a datagrid. It should
contain a drop down list of possible choices. I have an
EditCommandColumn.
The drop dow list column should initially contain the value of the field.
This works fine with
<ItemTemplate><%# Container.DataItem("NameType")%></ItemTemplate>

The desired effect is for the drop down list to databind to a query to
show
possible choices when the user clicks the edit link. I can not get a
reference to the drop down list when the user clicks edit. Does anyone
know
how to do this?

I tried page.findcontrol("controlname") and it does not work. Any ideas?
I
get a NullReference Error when I do this, because I guess the control
does
not exist on the page.

Thanks to everyone,
Chris

Nov 19 '05 #3
In the edit command handler try... DropDownList ddl = (DropDownList)
e.items.findcontrol("controlname")

Charlie
"Chris Kettenbach" <in**@piasd.net> wrote in message
news:n7********************@giganews.com...
Good Morning,
Quick question, I have an EditItemTemplate inside a datagrid. It should
contain a drop down list of possible choices. I have an
EditCommandColumn. The drop dow list column should initially contain the
value of the field. This works fine with
<ItemTemplate><%# Container.DataItem("NameType")%></ItemTemplate>

The desired effect is for the drop down list to databind to a query to
show possible choices when the user clicks the edit link. I can not get a
reference to the drop down list when the user clicks edit. Does anyone
know how to do this?

I tried page.findcontrol("controlname") and it does not work. Any ideas?
I get a NullReference Error when I do this, because I guess the control
does not exist on the page.

Thanks to everyone,
Chris

Nov 19 '05 #4
Did that did the trick
Try going through this article at:-
http://www.4guysfromrolla.com/webtech/050801-1.shtml
Hope that helps
Patrick

"Charlie@NISH" <cf*******@nish.org> wrote in message
news:On**************@TK2MSFTNGP12.phx.gbl...
In the edit command handler try... DropDownList ddl = (DropDownList)
e.items.findcontrol("controlname")

Charlie
"Chris Kettenbach" <in**@piasd.net> wrote in message
news:n7********************@giganews.com...
Good Morning,
Quick question, I have an EditItemTemplate inside a datagrid. It should
contain a drop down list of possible choices. I have an
EditCommandColumn. The drop dow list column should initially contain the
value of the field. This works fine with
<ItemTemplate><%# Container.DataItem("NameType")%></ItemTemplate>

The desired effect is for the drop down list to databind to a query to
show possible choices when the user clicks the edit link. I can not get a reference to the drop down list when the user clicks edit. Does anyone
know how to do this?

I tried page.findcontrol("controlname") and it does not work. Any ideas? I get a NullReference Error when I do this, because I guess the control
does not exist on the page.

Thanks to everyone,
Chris


Nov 19 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Dec | last post by:
Ok to simplify things I'll just give an example. This is pretty much what I want to do (minus the postcode): http://www.perrys.co.uk/usedcar?ID=F5J9BNNBMVK00DF I have relatively little...
1
by: Marlene harkcom | last post by:
I've got a datagrid with 5 bound columns in it as well as an edit/update/cancel column. I'm binding this to a dataset. One of the fields is always going to be one of three values. I want the...
3
by: Dharmen | last post by:
Hey Guys, I have a SQL database called price and a table called TB1, in it i have a column called "loc" I want to display the tiems in "loc" in a drop down list. I am able to do this in a...
2
by: Eric Dan | last post by:
Hi, Even tough I was able to implement what I want in a weird and non efficient way, I would like to get an opinion what is the right way to achieve my task: Scenario: • Display a DataGrid...
2
by: Joey Liang via DotNetMonster.com | last post by:
Hi all, I am new in asp.net, i encounter some problems in using drop down list and datagrid. I have manage to bind the data into datagrid but i wanted to bind the data into the datagrid accroding...
0
by: kaon | last post by:
Hi, Ive been looking for a way to capture an autopostback event of a dropdownlist in a datagrid control. the scenario is that, ive a datagrid, and there is a dropdownlist column in each of the row...
0
by: thebison | last post by:
Hi all, I hope someone can help with this relatively simple problem. I am building a timesheet application using ASP.NET C# with Visual Studio 2003.As it is only a protoype application, my...
0
by: weiwei | last post by:
Hi here is my scenario, I create a drop down list in itemtemplate.(that drop down is created from db), after user click edit command, my ideal plan is have another drop down list in...
22
by: Archanak | last post by:
Hi, I am using 2-level CSS Drop Down Menu in my perl/CGI program. here is the code. #!c:/perl/bin/perl.exe use CGI qw(:standard);
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.