dropdown in a grid

G

GaryB

I can put a dropdown in a grid column, databind it, and it will work but how
can I get the itemchanged event so that I can do something with it?
thanks,
G
 
J

Juno

Hi,

Try to catch ItemCommand event of datagrid, and use e.CommandSource to get
the handler of dropdown.

Hope it help.
 
J

Jos

GaryB said:
I can put a dropdown in a grid column, databind it, and it will work
but how can I get the itemchanged event so that I can do something
with it?
thanks,
G

Just attach the ItemChanged event as you would with a single
stand-alone dropdownlist.

The ItemChanged event will fire normally, the only problem is
that all of your dropdowns will fire the same event, so you
need to find out which one was changed.

One way to do this would be to use the ClientID property
(through Sender.ClientID), which contains a reference to the
item's index.
 
G

GaryB

The way I handle a normal ItemChanged Event is by using VS.NET, finding the
control in the left dropdown and selecting the event type in the righ
dropdown. But of course, the dropdown in my grid does not appear in that
list.

So, that's why I asked "how can I get the itemchanged event...."
G
 
S

Steven Cheng[MSFT]

Hi Gary,

As for the nested controls in the DataGrid or other template databound
control's template cell, we can directly assign the event handler in the
aspx page source , just like :

...................
<ItemTemplate>
<asp:DropDownList AutoPostBack="True" id="lstItems"
runat="server" OnSelectedIndexChanged="lstItems_SelectedIndexChanged"
....>
.............

define a handler in the page class, declare as protected or public(can't be
private since it need to be accessable from derived page class)
protected void lstItems_SelectedIndexChanged(object source, EventArgs e)
{
............
}

And here is a former thread which discussing on the same problem, you may
have a look for detailed reference:

#Dropdownlist in template column to fire a SelectedIndexChanged event
http://groups.google.com/groups?hl=en&lr=&ie=UTF-8&threadm=7wnkwsbiEHA.1280%
40cpmsftngxa10.phx.gbl&rnum=6&prev=/groups%3Fhl%3Den%26lr%3D%26ie%3DUTF-8%26
q%3DASP.NET%2Bdropdownlist%2Bin%2Bdatagrid%2Bsteven%2Bcheng

If you have any other questions, please feel free to post here .Thanks.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
G

GaryB

Steven,
a little late but thanks. I finally got back to that project where I needed
to do this an found your answer.
Gary
 
S

Steven Cheng[MSFT]

Thanks for your followup.

Also, if you meet any further problems, please always feel free to post
here.
Good LUck!

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,199
Latest member
AnyaFlynn6

Latest Threads

Top