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

  • SEARCH
  • Home
  • 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 340775
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T10:38:51+00:00 2026-05-12T10:38:51+00:00

I have created a gridview with a column of checkboxes. I want the user

  • 0

I have created a gridview with a column of checkboxes. I want the user to select the checkboxes, click the register button (outside the gridview), and have a title from the selected row displayed. From what I’ve read I should put the checkbox check in the button click event. I have done so, but apparently the only time it enters that event is at page load and right before the page loads, all the selected checkboxes are wiped. Therefore, my check for a selected checkbox never comes out true. Is there an event that would a better time to run this check, or perhaps a way to hold these values through the page load? The following isn’t all my code, just the affected portions.

    protected void regButton_Click(Object sender, EventArgs e)
    {
        StringBuilder regClasses = new StringBuilder();
        for (int i = 0; i < SQLQueryClassListings.Rows.Count; i++)
        {
            //Response.Write(SQLQueryClassListings.Rows[i].Cells[0].Text + " checkbox check ");
            GridViewRow checkRow = SQLQueryClassListings.Rows[i];
            bool reg = ((CheckBox)(checkRow.FindControl("RowCheckBox"))).Checked;
            if (reg)
            {
                regClasses.Append(SQLQueryClassListings.Rows[i].Cells[0].Text + " ");
            }
        }
        Response.Write(regClasses);
    }

<asp:GridView ID="SQLQueryClassListings" AutoGenerateColumns="false" runat="server" 
        BorderWidth="1px" BackColor="White" CellPadding="5" BorderColor="Black" RowStyle-BorderColor = "Black"
        HeaderStyle-BackColor="#0D69F2" HeaderStyle-ForeColor="White" AlternatingRowStyle-BackColor="#E8E8E8" HeaderStyle-BorderColor="Black" GridLines="Both">
        <Columns>
            <asp:BoundField HeaderText="Classes" DataField="LeafName" HeaderStyle-HorizontalAlign="Left" ItemStyle-Width="250" 
                ItemStyle-BorderColor="#ADADAD" HeaderStyle-BorderColor ="Black"/>
            <asp:BoundField HeaderText="Teacher" DataField="TeacherName" HeaderStyle-HorizontalAlign="Left" ItemStyle-Width="200" 
                ItemStyle-BorderColor="#ADADAD" HeaderStyle-BorderColor ="Black"/>
            <asp:BoundField HeaderText="Available" DataField="SemesterEnds" HeaderStyle-HorizontalAlign="Center"  
                ItemStyle-HorizontalAlign ="Center" ItemStyle-Width="150" ItemStyle-BorderColor="#ADADAD" HeaderStyle-BorderColor ="Black"/>
            <asp:HyperLinkField HeaderText="Course Description & Career Tracks" DataNavigateUrlFields="ApplicableTracks" 
                Text="See Description" HeaderStyle-HorizontalAlign="Center" ItemStyle-HorizontalAlign ="Center" ItemStyle-BorderColor="#ADADAD" HeaderStyle-BorderColor ="Black"/>
            <asp:TemplateField HeaderText="Register" HeaderStyle-BorderColor="Black" ItemStyle-BorderColor = "#ADADAD" ItemStyle-HorizontalAlign="Center">
                <ItemTemplate>
                    <asp:CheckBox runat="server" ID="RowCheckBox"/>
                </ItemTemplate>
            </asp:TemplateField>
        </Columns>
    </asp:GridView>
    <p>
    <asp:Button ID="Button1" runat="server" Text="Register" OnClientClick="return confirm('You have sucessfully registered!')"
        OnClick="regButton_Click" />
  • 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-12T10:38:51+00:00Added an answer on May 12, 2026 at 10:38 am

    It’s hard to know for sure without seeing more of your code, but it sounds like your page is re-binding the GridView on postbacks (such as your regButton_Click event). So it rebuilds the GridView every time the page loads – even after your user clicks the register button.

    If that is the case, you can fix this by changing the code you use to bind your GridView like this:

    if (!this.IsPostback) {
        SQLQueryClassListings.DataBind();
    }
    

    (This presumes that you have ViewState enabled for the page (or at least the GridView). There are other mechanisms you can use to communicate the client’s state (such as checkbox selections) to the server, but ViewState (for all its faults) is the default tool for doign so in ASP.NET.)

    A consequence is that the data shown in the GridView won’t be completely up-to-date, but if you can tolerate that, this is a simple way to accomplish what you want.

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

Sidebar

Related Questions

I have a column in a gridview of checkboxes. I want to be able
I have one GridView with 3 Column and 3 Rows I want to change
I have a GridView with one ButtonField column like this: I have already Created
I have a gridview and in that gridview i created a list of imagebuttons
I have a GridView to which I bind a dataTable that I manually created.
I have html that is dynamically created when I bind my gridview to a
I have created 3 classes as following Ext.mine.TextParent - Inherting from Textfield Ext.mine.child.TextChildA -
I have a GridView which retrieves data from a database. Users have roles, some
I have created: one master page and one content page called Detail. On Button
I have the the GridView's column looking like that: <Columns> <asp:TemplateField HeaderText=Opcje> <ItemTemplate> <asp:LinkButton

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.