473,473 Members | 2,170 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Datagrid - Dropdown OnSelectedIndexChanged

Hello,

I have a datagrid which contains DropDownList as follow:

<Columns>
<asp:TemplateColumn >
<ItemTemplate>
<asp:DropDownList id=ProductName
onSelectedIndexChanged=ProductName_IndexChange>... .

Now, in the method ProductName_IndexChange I want to write codes to
handle when user select the dropdown list. Assume there are 10 rows in
my datagrid, how do I know which row the user select from? Is there a
property in datagrid that gives me the item index when an event
happens?

Thanks so much.

Nov 19 '05 #1
1 1570
Hi Andy,

Adding a DropDownlist in the ItemTemplate (instead of the EditItemTemplate)
means that you have to add the event handler for the SelectedIndexChanged in
one of the following datagrid item events (e.g. OnItemCreated
OnItemDataBound). Which in turn means that upon postback you have to re-bind
the datagrid during the initialization of the page, as in those 2 examples:
http://www.societopia.net/Samples/DataGrid_6c.aspx
http://www.societopia.net/Samples/Da...Delegates.aspx

This however will prove challenging in 3 scencarios:

1- If you want to edit the grid by adding a EditCommandColumn because you
will lose the ViewState of the textboxes within the EditItemTemplate.

2- If data in the dropdownlists are repeated then you might consider a
client side approach by replacing the dropdownlist by a Textbox as in this
example http://www.societopia.net/samples/textbox.htm

3- Because the dropdownlist is displayed on each row (instead of only upon
edit), the page size might be large (imagine the size of the ViewState if you
display 100 records in each dropdownlist in a datagrid that has 20 rows)

--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com
"Andy" wrote:
Hello,

I have a datagrid which contains DropDownList as follow:

<Columns>
<asp:TemplateColumn >
<ItemTemplate>
<asp:DropDownList id=ProductName
onSelectedIndexChanged=ProductName_IndexChange>... .

Now, in the method ProductName_IndexChange I want to write codes to
handle when user select the dropdown list. Assume there are 10 rows in
my datagrid, how do I know which row the user select from? Is there a
property in datagrid that gives me the item index when an event
happens?

Thanks so much.

Nov 19 '05 #2

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

Similar topics

0
by: Ruby | last post by:
Hi All... I have problem with web form datagrid: I have 1 dropdownlist and 1 text box in datagrid footer. I want every time index change in dropdown list a value from database table stored in...
1
by: govindaraj_200152 | last post by:
Hi, I am using two Drodowns with ASP.NET Datagrid/(ASP.20 GridView) . What i want is , on selecting the first dropdown i want to populate the second dropdown based on the selection. The dropdown...
7
by: gn | last post by:
Hi have a dropdown list within a datagrid, based on what is selected in the list I want to populate another dropdownlist, the code to populate the dropdownlists is not the problem, my problem is...
3
by: Raja | last post by:
I have a simple question, I have a datagrid and inside the grid, i have List box. I am able to render the page with the datagrid and the lisbox values. Now, my question is how to trap the server...
3
by: Raja | last post by:
I have a datagrid, it has dropdown box as a column and i have one more column that has hyperlink. The NavigateURL for the hyperlink is to open a new window with a query stirng parameter as the...
2
by: tfsmag | last post by:
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...
3
by: danc | last post by:
I have a datagrid with a checkbox and dropdown list in each row. Both set AutoPostBack to true and ItemCommand and OnSelectedIndexChanged events for these controls works fine when DataGrid is not...
0
by: Andrus | last post by:
SWF ComboBox dropdown menu first item selection must open picklist. For this I use the following code: protected override void OnSelectedIndexChanged(System.EventArgs e) { if (SelectedIndex != 0...
5
by: =?Utf-8?B?Y2hlY2tyYWlzZXJAY29tbXVuaXR5Lm5vc3BhbQ== | last post by:
I have a VS 2008 ASP.NET webform that has a reportview tag on it, accessing an .RLDC report in local report. The columns for the report are essentially: Month Item #1 Item#2 Item#3 ...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
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...
1
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.