Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

DataGrid asp.net/vb.net radio button

Options
  • 13-01-2007 1:45pm
    #1
    Registered Users Posts: 7,677 ✭✭✭


    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,689 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 Posts: 7,677 ✭✭✭Trampas


    I changed it from a DataGrid to a DataView


  • Registered Users 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