How to obtain radiobutton value from a GridView

Discussion in 'ASP .Net Web Controls' started by Sergio, Jul 2, 2008.

  1. Sergio

    Sergio Guest

    Hi,
    i have a gridview whit 2 columns: a BoundField connected whit a database
    and a TemPlateField with 3 radio button like this

    <Columns>
    <asp:BoundField DataField="Domanda" HeaderText="Domanda" />
    <asp:TemplateField HeaderText="Seleziona">
    <ItemTemplate>
    <input name='<%# Eval("ID") %>' type="radio" value="0"
    />Insufficiente<br />
    <input name='<%# Eval("ID") %>' type="radio" value="1"
    checked="checked"/>Sufficiente<br />
    <input name='<%# Eval("ID") %>' type="radio" value="2"
    />Buono
    </ItemTemplate>
    </asp:TemplateField>
    </Columns>

    From code i can read value from the 1st column and , e.g., put it on a listbox

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As
    EventArgs) Handles Button1.Click
    For i = 0 To GridView1.Rows.Count - 1
    ListBox1.Items.Add(GridView1.Rows(i).Cells(0).Text
    Next
    End Sub

    but i don't have any idea to read the value of the RadioButton!!!
    My be i'm confusing with asp (not aspx) but in aspx i don't know what i must
    to do :-(
    I'm using vb 2008. Thank's
    Sergio, Jul 2, 2008
    #1
    1. Advertising

  2. Sergio

    Evan Freeman Guest

    Well depends on where you want to read it. Basically you have input fields
    so they should be on the form in the code behind. If thats where you want
    the value.
    ANyhow I forget the syntax for processing the form post on the code behind,
    but thats where the value of the radio buttons can be read from the easiest.
    --
    Evan Freeman

    http://evanfreeman.blogspot.com
    "Sergio" <> wrote in message
    news:...
    > Hi,
    > i have a gridview whit 2 columns: a BoundField connected whit a database
    > and a TemPlateField with 3 radio button like this
    >
    > <Columns>
    > <asp:BoundField DataField="Domanda" HeaderText="Domanda"
    > />
    > <asp:TemplateField HeaderText="Seleziona">
    > <ItemTemplate>
    > <input name='<%# Eval("ID") %>' type="radio"
    > value="0"
    > />Insufficiente<br />
    > <input name='<%# Eval("ID") %>' type="radio"
    > value="1"
    > checked="checked"/>Sufficiente<br />
    > <input name='<%# Eval("ID") %>' type="radio"
    > value="2"
    > />Buono
    > </ItemTemplate>
    > </asp:TemplateField>
    > </Columns>
    >
    > From code i can read value from the 1st column and , e.g., put it on a
    > listbox
    >
    > Protected Sub Button1_Click(ByVal sender As Object, ByVal e As
    > EventArgs) Handles Button1.Click
    > For i = 0 To GridView1.Rows.Count - 1
    > ListBox1.Items.Add(GridView1.Rows(i).Cells(0).Text
    > Next
    > End Sub
    >
    > but i don't have any idea to read the value of the RadioButton!!!
    > My be i'm confusing with asp (not aspx) but in aspx i don't know what i
    > must
    > to do :-(
    > I'm using vb 2008. Thank's
    Evan Freeman, Jul 2, 2008
    #2
    1. Advertising

  3. Sergio

    Stan Guest

    On 2 Jul, 11:50, Sergio <> wrote:
    > Hi,
    > i have a gridview  whit 2 columns: a BoundField connected whit a database
    > and a TemPlateField with 3 radio button like this
    >
    >                   <Columns>
    >                   <asp:BoundField DataField="Domanda"HeaderText="Domanda" />
    >                   <asp:TemplateField HeaderText="Seleziona">                
    >                     <ItemTemplate>
    >                       <input name='<%# Eval("ID")%>' type="radio" value="0"
    > />Insufficiente<br />
    >                       <input name='<%# Eval("ID")%>' type="radio" value="1"
    > checked="checked"/>Sufficiente<br />
    >                       <input name='<%# Eval("ID")%>' type="radio" value="2"
    > />Buono
    >                     </ItemTemplate>
    >                   </asp:TemplateField>
    >                   </Columns>
    >
    > From code i can read value from the 1st column and , e.g., put it on a listbox
    >
    >     Protected Sub Button1_Click(ByVal sender As Object, ByVal e As
    > EventArgs) Handles Button1.Click
    >         For i = 0 To GridView1.Rows.Count - 1
    >             ListBox1.Items.Add(GridView1.Rows(i).Cells(0).Text
    >         Next
    >     End Sub
    >
    > but i don't have any idea to read the value of the RadioButton!!!
    > My be i'm confusing with asp (not aspx) but in aspx i don't know what i must
    > to do :-(
    > I'm using vb 2008. Thank's


    For a templated field you need to use the FindControl method of the
    Cell object to retrieve the RadioButtonList. Give the control a
    deliberately chosen name and use that as a parameter.

    HTH
    Stan, Jul 7, 2008
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    1
    Views:
    689
  2. Merichel

    RadioButton in a GridView

    Merichel, Aug 2, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    13,197
    SerhaD
    Aug 2, 2006
  3. Patrik
    Replies:
    4
    Views:
    7,176
    Ken Cox [Microsoft MVP]
    Sep 7, 2006
  4. YSUT

    Displaying Gridview in RadioButton format

    YSUT, Jan 23, 2006, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    108
  5. gauty
    Replies:
    1
    Views:
    855
    Kashish Malhotra
    Apr 29, 2010
Loading...

Share This Page