rowselect in gridview


E

Eric Effer

Hi everyone

I am tryin to get the selected index from this gridview while selecting the
radiobuttonlist. I dont want to use a button for the row though. Anyone
knows how to do this?

thnks

Eric


<%@ Page Language="VB" %>

<script runat="server">


Protected Sub rbl_SelectedIndexChanged(ByVal sender As Object, ByVal e As
System.EventArgs)

Dim index As Integer

End Sub

</script>

<html>

<body>

<form id="form1" runat="server">

<table width="100%">

<tr>

<td style="width: 50%">

<asp:GridView ID="CustomersGridView" DataSourceID="CustomersSource"
AllowPaging="true"

AutoGenerateColumns="false" runat="server">

<Columns>

<asp:BoundField DataField="CustomerID" HeaderText="Customer ID" />

<asp:BoundField DataField="CompanyName" HeaderText="Company Name" />

<asp:BoundField DataField="City" HeaderText="City" />

<asp:TemplateField>

<ItemTemplate>

<asp:RadioButtonList ID="rbl" runat="server" AutoPostBack="true"
OnSelectedIndexChanged="rbl_SelectedIndexChanged">

<asp:ListItem>

one

</asp:ListItem>

<asp:ListItem>two</asp:ListItem>

</asp:RadioButtonList>

</ItemTemplate>

</asp:TemplateField>

</Columns>

</asp:GridView>

</td>

<td style="vertical-align: top; width: 51%">

</td>

</tr>

</table>

<asp:SqlDataSource ID="CustomersSource" SelectCommand="select * From
Customers"

connectionstring="<%$ ConnectionStrings:NorthWindConnectionString%>"
runat="server" />

</form>

</body>

</html>
 
Ad

Advertisements

E

Eliyahu Goldin

If I understand you correctly, you need to find the index of the row with
the selected radiobutton.

The rbl_SelectedIndexChanged event handler gets a reference to the
radiobutton that initiated the event. You can navigate to the datagrid row
that contains the button via the Parent property. Set a breakpoint and see
in the debugger how many times you need to call Parent to get from the
radiobutton to the row. Once you have the row, its RowIndex property will
tell you the index.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
 

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

Top