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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T13:14:44+00:00 2026-05-25T13:14:44+00:00

I have a GridView that displays data on three columns. On the third column

  • 0

I have a GridView that displays data on three columns. On the third column I have a CheckBox. I have two things that I need to achieve

  1. CheckBox will be checked based on the column value (1,0)
  2. If it is checked the rest of the two columns should display #### However the data for the two columns should remain in the database.

How can this be achieved?

Can I find the CheckBox on RowDataBound event and check the value and make the CheckBox checked and unchecked? How about making the other columns ####?

NEW Comments:

string str = ((System.Data.DataRowView)(e.Row.DataItem)).Row.ItemArray[2].ToString();

this helps to set the checkbox checked or not.

if checked is true I am trying the following.

((System.Data.DataRowView)(e.Row.DataItem)).Row.ItemArray[0] = "#####";
((System.Data.DataRowView)(e.Row.DataItem)).Row.ItemArray[1] = "#####";
((System.Data.DataRowView)(e.Row.DataItem)).Row.AcceptChanges();

It is displaying the gridview checkbox as checked but the column value is not changed to “####”

  • 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-25T13:14:45+00:00Added an answer on May 25, 2026 at 1:14 pm

    You can turn your item columns into TemplateColumns and do the following which will localize your code to the control level and you don’t have to worry about all the searching. I pefer to never use the built in column types because there are usually future enhancements that require changing the columns to TemplateColumns anyways. It also gives you a lot of flexibiltiy on useage.

    Here is an example:

    <asp:GridView ID="grdYourGrid" runat="server" AutoGenerateColumns="False">
        <Columns>
            <asp:TemplateField HeaderText="YourField1">
                <ItemTemplate>
                    <asp:Literal runat="server" ID="ltYourField1" 
                        OnDataBinding="ltYourField1_DataBinding" />
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="YourField2">
                <ItemTemplate>
                    <asp:Literal runat="server" ID="ltYourField2" 
                        OnDataBinding="ltYourField2_DataBinding" />
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="YourCheckBoxField">
                <ItemTemplate>
                    <asp:CheckBox runat="server" ID="chkYourCheckBoxField" 
                        OnDataBinding="chkYourCheckBoxField_DataBinding" />
                </ItemTemplate>
            </asp:TemplateField>
        </Columns>
    </asp:GridView>
    

    Then in your codebehind implement each control’s OnDataBinding:

    protected void ltYourField1_DataBinding(object sender, System.EventArgs e)
    {
        Literal lt = (Literal)(sender);
        lt.Text = (bool)(Eval("YourCheckBoxField")) ?
            "##########" : Eval("YourField1");
    }
    
    protected void ltYourField2_DataBinding(object sender, System.EventArgs e)
    {
        Literal lt = (Literal)(sender);
        lt.Text = (bool)(Eval("YourCheckBoxField")) ?
            "##########" : Eval("YourField2");
    }
    
    protected void chkYourCheckBoxField_DataBinding(object sender, System.EventArgs e)
    {
        CheckBox chk = (CheckBox)(sender);
        chk.Checked = (bool)(Eval("YourCheckBoxField"));
    }
    

    The advantages to doing it this way is your could replace code easily as it is all isolated and has no ‘searching’ for expected controls. I very rarely use the RowDataBound event because it makes you have to write specific code to look for the controls and it makes more sense to me to have the code localized to the control. If someone changes something they know there are ONLY affecting that one control instead of everything on the row possibly as a side effect. You could also use the <%# method and do the Evals right in the markup but I personally prefer to never have any code in the aspx markup at all.

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

Sidebar

Related Questions

I have a gridview that displays items details, I added two template fields one
I have a gridview that I have added a checkbox column using a templatefield
I have a gridview that displays data from a database. The datbase stores the
In my Webforms 3.5 application, I have a GridView of users that displays the
I have a grideview that displays rows that will be deleted across servers by
I have a GridView that allows editing the values in every column, in every
I am creating a GridView/DetailsView page. I have a grid that displays a bunch
I have a Gridview that displays paged results from a search query. The problem
I have a basic GridView that displays a list of tasks to do (just
I have a gridview that imports data from a remote database, this is working

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.