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

Drop down list on each GridView row

P: n/a
Hi. I have a read only GridView. For each row I want to display a drop down
list which contains a list of actions the user can select from for that
particular row. E.g. "view details". When they select an action in the drop
down list I want to do a post back. How will I know which row they made the
selection in?

Is there a way to embed the row Id in the drop down list so it gets sent
back to the server?

Thanks
Sep 22 '07 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Hi,

you don't need the row ID. Instead handle DropDownList's
SelectedIndexChanged event and in that get reference to the DropDownList
raising the event, you'd get that via sender argument (first argument to the
event handling method)

[VB.NET]
Dim ddl As DropDownList = CType(sender, DropDownList)

[C#]
DropDownList ddl = (DropDownList)sender;

Then trick is to know how databound controls work. The GridViewRow is naming
container of your DropDownList

[VB.NET]
Dim row As GridViewRow = CType(ddl.NamingContainer, GridViewRow)

[C#]
GridViewRow row = (GridViewRow)ddl.NamingContainer;

I've explained some background for this type of scenarios:

Understanding the naming container hierarchy of ASP.NET databound controls
http://aspadvice.com/blogs/joteke/ar...-controls.aspx

--
Teemu Keiski
AspInsider, ASP.NET MVP
http://blogs.aspadvice.com/joteke
http://teemukeiski.net

"McGeeky" <an**@hotmail.comwrote in message
news:%2******************@TK2MSFTNGP02.phx.gbl...
Hi. I have a read only GridView. For each row I want to display a drop
down list which contains a list of actions the user can select from for
that particular row. E.g. "view details". When they select an action in
the drop down list I want to do a post back. How will I know which row
they made the selection in?

Is there a way to embed the row Id in the drop down list so it gets sent
back to the server?

Thanks

Sep 23 '07 #2

P: n/a
Cool. Thanks so much for that!!

"Teemu Keiski" <jo****@aspalliance.comwrote in message
news:uG*************@TK2MSFTNGP05.phx.gbl...
Hi,

you don't need the row ID. Instead handle DropDownList's
SelectedIndexChanged event and in that get reference to the DropDownList
raising the event, you'd get that via sender argument (first argument to
the event handling method)

[VB.NET]
Dim ddl As DropDownList = CType(sender, DropDownList)

[C#]
DropDownList ddl = (DropDownList)sender;

Then trick is to know how databound controls work. The GridViewRow is
naming container of your DropDownList

[VB.NET]
Dim row As GridViewRow = CType(ddl.NamingContainer, GridViewRow)

[C#]
GridViewRow row = (GridViewRow)ddl.NamingContainer;

I've explained some background for this type of scenarios:

Understanding the naming container hierarchy of ASP.NET databound controls
http://aspadvice.com/blogs/joteke/ar...-controls.aspx

--
Teemu Keiski
AspInsider, ASP.NET MVP
http://blogs.aspadvice.com/joteke
http://teemukeiski.net

"McGeeky" <an**@hotmail.comwrote in message
news:%2******************@TK2MSFTNGP02.phx.gbl...
>Hi. I have a read only GridView. For each row I want to display a drop
down list which contains a list of actions the user can select from for
that particular row. E.g. "view details". When they select an action in
the drop down list I want to do a post back. How will I know which row
they made the selection in?

Is there a way to embed the row Id in the drop down list so it gets sent
back to the server?

Thanks


Sep 23 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.