How to obtain radiobutton value from a GridView

S

Sergio

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
 
E

Evan Freeman

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.
 
S

Stan

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
 

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

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top