DropDown in DataGrid

R

RS

Hello,
I need to add a dropdown list to datagrid. Once page is displayed on change
of the selection of the dropdown for that row, I need to be able to capture
the value of the dropdown and do some things in the code behind. I got
Dropdown list to show up in the grid and all values that I need are there.
What I am missing is capture of onchange event.

Does anyone have any idea how to capture event on the page behind?

Thanks so much to everyone!!
 
R

Richard Dudley

There's a great series on doing stuff like this as 4guysfromrolla.com. It's
a long series, but is a good guide. He turned it into a book called
"ASP.NET Data Web Controls Kick Start", which is for ASP.NET 1.1, so unless
you're going to be with 1.1 for a long while, I'd stick with the on-line
articles (I did buy the book about a year ago, and it is well worth it, but
the new 2.0 framework is now out, and the book isn't so relevant to that).
 
A

agapeton

Here's one way to do it... This is a 2.0 Gridview...

<asp:GridView ID="gvPeople" runat="server"
AutoGenerateColumns="false">
<Columns>
<asp:BoundField DataField="Name" HeaderText="Person
Name" />
<asp:TemplateField HeaderText="Best Friend">
<ItemTemplate>
<asp:DropDownList ID="ddlFriend"
runat="server"
AppendDataBoundItems="true"
DataTextField="Name"
OnSelectedIndexChanged="Runit"
DataValueField="Name">
<asp:ListItem Text="-"
Value="0"></asp:ListItem>
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>

Or you can always do something that looks like this...

((DropDownList)gvPeople.Controls[0].Controls[n].Controls[1].FindControl("ddlFriend")).SelectedIndexChanged
+= new EventHandler(Default4_SelectedIndexChanged);

I think declaratively is easier myself... believe me it's even EASIER
in .NET 2.0 with the data source controls.
 

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

No members online now.

Forum statistics

Threads
473,996
Messages
2,570,238
Members
46,826
Latest member
robinsontor

Latest Threads

Top