473,320 Members | 1,694 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,320 software developers and data experts.

problem with dropdownlist inside of datagrid

Hello,

I'm still relatively new to asp.net and i'm having troubles with a
dropdownlist in a datagrid. Here is the code for the dropdownlist

---------------------------------
<asp:DropDownList Runat="server"
OnSelectedIndexChanged="ddlSelectionChanged" SelectedValue='<%#
DataBinder.Eval(Container.DataItem, "ACTIVE")%>' ID="DropDown"
AutoPostBack="True">
<asp:ListItem Value="1">Enabled</asp:ListItem>
<asp:ListItem Value="0">Disabled</asp:ListItem>
<asp:ListItem Value="2">Deleted</asp:ListItem>
</asp:DropDownList>
---------------------------------

This renders fine, and the proper index is selected when the page comes
up, the difficulty i'm having is capturing the row's unique id field to
update the database when they select a new index and fire the
"ddlSelectionChanged".

Here is the codebehind code for the ddlSelectionChanged event

---------------------------
Protected Sub ddlSelectionChanged(ByVal sender As Object, ByVal e As
System.EventArgs) Handles DropDown.SelectedIndexChanged
Dim ddl As DropDownList
ddl = CType(sender, DropDownList)
Dim user_id as integer = (??? this is where i can't figure out
how to get the row id)
End Sub
---------------------------

The event does fire, I made sure of that by using a label and wrote
something to the label at the end of the event.

Any help here would be greatly appreciated as I am about ready to pull
my hair out!

Thanks,
Jeff T.

Nov 19 '05 #1
2 1048
Hi,

Despite that event is fired by the DDL, DDL is still located in the DataGrid
and especially in its control hierarchy.Therefore you are interested in the
DataGridItem which contains the DDL. The DataGridItem could be get using:

Dim dgi As DataGridItem = CType(ddl.Parent.Parent,DataGridItem)

(or ddl.NamingContainer instead of ddl.Parent.Parent)

If you have assigned the ID into DataKeys of Datagrid (means DataKeyField is
set), you could get it from the collection using

Dim user_id As Integer=CInt(dgInstance.DataKeys(dgi.ItemIndex))

And again if the ID is stored into a control or a cell, you could access
them also via the DatagridItem.

--
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU
Nov 19 '05 #2
that worked! holy cow, if you were here i'd take you out for a beer :P

thanks again!

Nov 19 '05 #3

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

Similar topics

2
by: Dominic | last post by:
Hi guys, I'm not sure if this question belongs to FAQ, but I couldn't find a concrete answer. I created a Datagrid control using ItemTemplate, but it's NOT a in-place editing datagrid. One of...
2
by: Ali | last post by:
I am adding a DropDownList control to my DataGrid footer template. I load my DropDownList using a function that returns an arrayList. I can see all my items in the DropDownList, but when I select...
8
by: David | last post by:
This is something I had never seen before. On an aspx page, upon pressing a link button for which I have an event handler in the code behind, the screen shows nothing but a line that says "true"...
1
by: George Durzi | last post by:
When my datagrid is in edit mode, one of my columns is edited using a drop down list. I'm able to bind the DropDownList to a DataSource when in edit mode. HOWEVER, I can't preset the...
2
by: jason | last post by:
Pardon my ignorance on this. The below code works, except, when I edit a record and update the two drop downs take the first entry in the dropdownlist if not selected. I'd also like the dropdown to...
0
by: Luis Esteban Valencia | last post by:
Hello. I have a datagrid with one row. I have a button that adds a new row. I am trying to implement that when the user selects one product it must change the price on the quantity column. Anyway...
15
by: glenn | last post by:
Hi folks, I have a DropDownList in a DataGrid that is populated from records in a database. I want to add a value that might be a string such as "Select a Company" for the first item since an...
2
by: glenn | last post by:
Hi folks, Page_Load has the following definition: Sub Page_Load(sender as Object, e as EventArgs) As such, we are unable to instantiate a control that is inside a DataGrid since the e...
2
by: steven | last post by:
i've got a dropDownList that I'm trying to populate from my code behind as follows: uxVehicleColourEdit.DataSource = oDsLookups.Tables; if the dropDown is placed inside a datagrid, i get...
0
by: stevem2112 | last post by:
I have a datagrid with 2 Template columns. One column has DropDownLists and the other has Textboxes. I bind each DDL in the ItemCreated event. This datagrid is inside a UserControl that is inside...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.