Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

DataGrid asp.net/vb.net radio button

  • 13-01-2007 01:45PM
    #1
    Registered Users, Registered Users 2 Posts: 8,588 ✭✭✭


    Hi all,

    I am using using ASP.NET 2 and VB.Net 2005.

    I have a radio button column on the grid.

    When a person its the submit button I am trying to find out what row is selected on the DataGrid.

    I have the following code but it keeps coming back with nothing

    ASP.NET
    
    <asp:DataGrid ID="dtgDetails" runat="server" AutoGenerateColumns="false">
                        <Columns>
                            <asp:TemplateColumn >
                                <ItemTemplate >
                                    <asp:RadioButton id="OutRadioInfo" runat="server" value='<%# Eval("RadioInfo") %>'  />
                                </ItemTemplate>
                            </asp:TemplateColumn>
                            <asp:BoundColumn DataField="Day" HeaderText="Day"/>
                            <asp:BoundColumn DataField="Date" HeaderText="Date"/>
                            <asp:BoundColumn DataField="Month" HeaderText="Month" />
                            <asp:BoundColumn DataField="DeptTime" HeaderText="Departure Time" />
                            <asp:BoundColumn DataField="ArriveTime" HeaderText="Arrival Time" />
                            <asp:BoundColumn DataField="Price" HeaderText="Price" />
                            <asp:BoundColumn DataField="RadioInfo" HeaderText="RadioInfo"/> 
                        </Columns>                  
                    </asp:DataGrid>
    
    

    VB.NET
    
    Protected Sub Purchase_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Purchase.Click
    
    Dim selectedValue As String = Request.Form("OutRadioInfo")
    
    End Sub
    
    

    Thanks


Comments

  • Moderators, Society & Culture Moderators Posts: 9,688 Mod ✭✭✭✭stevenmu


    is it possible for you to approach it a slightly different way? What you could do is have a select column instead of the radio one, this will select a row and submit allowing you to trap the rowselected event.


  • Closed Accounts Posts: 1,106 ✭✭✭MoominPapa


    I'm pretty new to asp but this is how I check for selected check boxes, I imagine its pretty similar for radio buttons:

    Sub Check(sender As Object, e As EventArgs)
    Dim chkSelected As CheckBox
    Dim dgi As DataGridItem
    for each dgi in MyDataGrid.Items
    chkSelected = dgi.FindControl("mycheckbox")
    If chkSelected.Checked Then
    dgi.Cells(5).Text = "Checked"
    else
    dgi.Cells(5).Text ="Not Checked"
    end if
    next
    End Sub

    <asp:TemplateColumn HeaderText="Check Box column">
    <ItemTemplate>
    <asp:CheckBox id="mycheckbox" AutoPostBack="True" OnCheckedChanged="Check" runat="server" />
    </ItemTemplate>
    </asp:TemplateColumn>


  • Registered Users, Registered Users 2 Posts: 8,588 ✭✭✭Trampas


    I changed it from a DataGrid to a DataView


  • Registered Users, Registered Users 2 Posts: 2,931 ✭✭✭Ginger


    You can do this in the SelectedIndexChanging event for the datagrid

    Dim gvrRowDetails As GridViewRow

    grvRowDetails = dgr.Rows(Me.dgr.SelectedIndex)
    blChk = grvRowDetails.FindControl("chkbox")


Advertisement