Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1089957
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T23:18:11+00:00 2026-05-16T23:18:11+00:00

I have radio button list in a gridview that needs to be bound to

  • 0

I have radio button list in a gridview that needs to be bound to a column. If the value in a column is 0, the first radio button is selected, if 1, the other is selected.

This is the code, some of it is partially removed because it is not necessary

<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<>"
    SelectCommand="" SelectCommandType="StoredProcedure" UpdateCommand="">
    <SelectParameters></SelectParameters>
    <UpdateParameters></UpdateParameters>
</asp:SqlDataSource>
<asp:GridView ID="gvBlockDetail" runat="server" AutoGenerateColumns="False"
    DataKeyNames="curriculumyear,electiveid,blockid" DataSourceID="SqlDataSource1"
    HorizontalAlign="Left" CellPadding="1" CssClass="news" GridLines="None" 
    BorderColor="#ebe9e2" BorderStyle="Solid" BorderWidth="1" >
    <AlternatingRowStyle BackColor="#ebe9e2" />
    <HeaderStyle BackColor="#660000" ForeColor="White" Font-Size="Small" />
    <RowStyle Font-Size="9pt" Wrap="false" ForeColor="#660000" HorizontalAlign="Center" />
    <Columns>
        <asp:TemplateField HeaderText="Add/Remove">
            <HeaderStyle Width="15%" />
            <ItemStyle Wrap="false" Width="80px" />
            <ItemTemplate>
                <asp:RadioButtonList ID="rblAddRemove" runat="server" RepeatDirection="Horizontal">
                    <asp:ListItem Text="Add" Value="0"></asp:ListItem>
                    <asp:ListItem Text="Remove" Value="1"></asp:ListItem>
                </asp:RadioButtonList>
            </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField HeaderText="Block">
            <HeaderStyle Width="15%" />
            <ItemStyle Wrap="false" Width="50px"  />
            <ItemTemplate>
                <asp:Label ID="lblBlock" runat="server" Text='<%# Bind("Block") %>'></asp:Label>
                <asp:Label ID="lblSection" runat="server" Text='<%# Bind("Section") %>'></asp:Label>
            </ItemTemplate>
        </asp:TemplateField>
        <asp:BoundField DataField="daterange" HeaderText="Dates" ReadOnly="True"  SortExpression="daterange" />
        <asp:BoundField DataField="credithours" HeaderText="Credit Hrs" 
                                                    SortExpression="credithours" HeaderStyle-Width="10%" ItemStyle-Width="10%" />
        <asp:TemplateField HeaderText="Students&lt;br&gt;Per Block" HeaderStyle-Width="15%" SortExpression="studentsperblock">
            <EditItemTemplate>
                <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("studentsperblock") %>'></asp:TextBox>
            </EditItemTemplate>
            <ItemTemplate>
                <asp:TextBox ID="txtStudentsPerBlock" runat="server" MaxLength="3" Width="40px" Text='<%# Bind("studentsperblock") %>'></asp:TextBox>
            </ItemTemplate>
        </asp:TemplateField>    
        <asp:BoundField DataField="enrolled" HeaderText="Enrolled" ReadOnly="True"
                                                    SortExpression="enrolled" ItemStyle-Width="200px" />  
        <asp:BoundField DataField="blockid" HeaderText="blockid" ReadOnly="True" 
                                                    SortExpression="blockid" Visible="false" />
    </Columns>
</asp:GridView>

Codebehind:

Protected Sub gvBlockDetail_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gvBlockDetail.RowDataBound

End Sub
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T23:18:12+00:00Added an answer on May 16, 2026 at 11:18 pm

    You could try inline binding:

    <asp:RadioButtonList ID="rblAddRemove" runat="server" RepeatDirection="Horizontal" SelectedValue='<%# Bind("YOURCOLUMN") %>'>
       <asp:ListItem Text="Add" Value="0"></asp:ListItem>
        <asp:ListItem Text="Remove" Value="1"></asp:ListItem>
    </asp:RadioButtonList>
    

    Where yourcolumn is the int column you described.

    Or via the RowDataBound event. (Pseudocode, the properties might have a different name and I’m using C#)

    Protected Sub gvBlockDetail_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gvBlockDetail.RowDataBound
      if(e.Row.RowType == RowType.DataRow)
      {
       RadioButtonList rbl = e.Row.FindControl("rblAddRemove") as RadioButtonList;
       if(rbl != null)
       {
         rbl.SelectedValue = ((YOURDATAITEM)(e.Row.DataItem).YourProperty.ToString();
       }
      }
    End Sub
    

    Edit: I see you aren’t using custom classes. You need to adjust the line with YOURDATAITEM. Use quick watch to get to know how to cast the object to get ahold of the desired property.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have radio button list which has id as the value, I want to
I have a list of 3 radio buttons with the 1st radio that's selected
I have a radio button list and some of the labels are quite long
I have a radiobutton list and on click on the radio button item I
I have a radio button on my Windows Form. How can I determine if
I have the following markup, and I want to make the All radio button
I have a form with some radio buttons that are disabled by default. When
I have a swing application that includes radio buttons on a form. I have
This query is related to this one I asked yesterday. I have a radio
Good afternoon all. I have a page that displays data in a gridview based

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.