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 6059151
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T08:40:43+00:00 2026-05-23T08:40:43+00:00

I have a gridview control with a checkbox field and several bound fields. The

  • 0

I have a gridview control with a checkbox field and several bound fields. The checkbox field does not directly map to a field in the database. Rather, i want to read a value from a field in the database and “check” some of the checkboxes.

For example, given the following data from the database -> datatable

        PROCESSED   NAME             DATE            
            Y       Mickey Mouse     11/15/2011
            N       Donald Duck      4/01/2012
            Y       James Bond       5/02/2011

I would like the gridview to display a checkbox and set the value of boxes to UNCHECKED where PROCESSED = N and for PROCESSED = Y either have an uneditable checkbox or no checkbox at all.

        PROCESSED   NAME             DATE            
           [/]       Mickey Mouse     11/15/2011
           [ ]       Donald Duck      4/01/2012
           [/]       James Bond       5/02/2011

To populate the gridview, a SQL stmt is run against a database, and the result of the SQL query is stored in a datatable. Before binding the datatable to the gridview, i would like to check the “processed” field and set the checkbox based on that value.

Here is the gridview control (shortened for clarity):

<asp:GridView ID="gridview_all_applicants" runat="server" AllowPaging="True">
        <Columns>
          <asp:TemplateField HeaderText="Complete">
                <ItemTemplate>
                    <asp:CheckBox ID="process_flag" runat="server" />
                </ItemTemplate>
          </asp:TemplateField>
          <asp:BoundField DataField="lastname" HeaderText="Last Name" ReadOnly="True"  SortExpression="lastname" />

Here is what i have so far in the code behind

 SqlCommand cmd = new SqlCommand(sql query here);
 SqlDataAdapter da = new SqlDataAdapter();
 DataTable dt = new DataTable();
 da.SelectCommand = cmd;
 // Save results of select statement into a datatable
 da.Fill(dt);
 foreach (DataRow r in dt.Rows)
 {
        // do some processing of data returned from query
        // read the char value from the returned data and set checkbox

             procflag = r["process_flag"].ToString().ToLower();
             CheckBox chkbox = new CheckBox();
             if (procflag == null || procflag == "n")
             {
                // SET CHECKBOX TO "NOT CHECKED"        

              }
              else
              {
                 // SET CHECKBOX TO "CHECKED" AND MAKE IT UNCLICKABLE
                 // ----OR---- DO NOT DISPLAY CHECKBOX AT ALL.

               }
     } // end for each


          gridview_all_applicants.DataSource = dt;
          gridview_all_applicants.DataBind(); 

any help is greatly appreciated.

  • 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-23T08:40:43+00:00Added an answer on May 23, 2026 at 8:40 am

    You can do it like this:

    First in sql server:

    
    SELECT 
        CAST(CASE PROCESSED WHEN 'Y' THEN 1 ELSE 0 END AS BIT) AS PROCESSED
        NAME
        DATE
    FROM ExampleTable
    

    in c# code:

    
    SqlCommand cmd = new SqlCommand(sql query here); 
    SqlDataAdapter da = new SqlDataAdapter(); 
    DataTable dt = new DataTable(); 
    da.SelectCommand = cmd; 
    
    // Save results of select statement into a datatable 
    da.Fill(dt);
    
    gridview_all_applicants.DataSource = dt;          
    gridview_all_applicants.DataBind(); 
    

    and finally in aspx:

    <asp:TemplateField HeaderText="Complete">
    <ItemTemplate>
        <asp:CheckBox ID="process_flag" runat="server" Checked='<%# bool.Parse(Eval("PROCESSED").ToString()) %>' Enable='<%# !bool.Parse(Eval("PROCESSED").ToString()) %>'/>
    </ItemTemplate>
    

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

Sidebar

Related Questions

I have a GridView control on an ASP page, which I've bound to a
I have a grid view control with Template Field containing Item Template as Checkbox
I have a data bound GridView control, in which I am able to disable
I have been playing around with the WPF GridView control (DesktopUI not Silverlight) and
I have a gridview control and I would like the field Title to be
I have a GridView control in an Asp.net application, that has a <asp:buttonField> of
I have a gridview control that can get loaded with multiple pages worth of
I have a GridView control on my page that I have defined a number
I have a form that contains a GridView control which is databound to an
I have an ASP.NET page with a gridview control on it with a CommandButton

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.