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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T16:51:21+00:00 2026-05-15T16:51:21+00:00

I have a gridview in which the first column in a checkbox. The grid

  • 0

I have a gridview in which the first column in a checkbox. The grid displays one or more records that are returned from the database upon user search (the grid is populated in a proc called “protected void DisplayGridData()“). If the “inactive” column of that record is “1”, I would like to have the checkbox disabled. How can I accomplish that?

The html code is:

            <asp:GridView ID="gvCanadaOrders" runat="server" AutoGenerateColumns="False" CellPadding="2" CellSpacing="2" GridLines="None" Width="100%" AllowPaging="True" PageSize="30"
                onpageindexchanging="gvCanadaOrders_PageIndexChanging" ForeColor="#333333" DataKeyNames="RecID">
                <Columns>
                    <asp:TemplateField HeaderText="Disable" >
                        <ItemTemplate>
                            <asp:CheckBox ID="cbPONumber" runat="server"/>
                        </ItemTemplate>
                    </asp:TemplateField>
                    <%--<asp:BoundField DataField="Rec_ID" HeaderText="Rec_ID" HtmlEncode="False"></asp:BoundField>--%>
                    <asp:BoundField DataField="Inactive" HeaderText="Inactive" HtmlEncode="False" ></asp:BoundField>
                    <asp:BoundField DataField="PO_Number" HeaderText="PO Number" HtmlEncode="False" ></asp:BoundField>
                    <asp:BoundField DataField="VENDOR_NAME" HeaderText="Vendor Name"></asp:BoundField>
                    <asp:BoundField DataField="ITEM_DESC" HeaderText="Item Description"></asp:BoundField>
                    <asp:BoundField DataField="MFG_PART_NO" HeaderText="MFG Part Number"></asp:BoundField>
                    <asp:BoundField DataField="System_DATE" HeaderText="System Date"></asp:BoundField>
                    <asp:BoundField DataField="PRINT_DATE" HeaderText="Print Date"></asp:BoundField>
                </Columns>
                <FooterStyle CssClass="GridFooter" BackColor="#990000" Font-Bold="True" ForeColor="White" />
                <PagerStyle CssClass="GridPager" ForeColor="#333333" BackColor="#FFCC66" HorizontalAlign="Center" />
                <SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="Navy" />
                <HeaderStyle CssClass="GridHeader" BackColor="#990000" Font-Bold="True" ForeColor="White"  />
                <RowStyle CssClass="GridItem" BackColor="#FFFBD6" ForeColor="#333333" />
                <AlternatingRowStyle  CssClass="GridAltItem" BackColor="White" />
            </asp:GridView>

The code that loads the gridview is:

protected void btnDisable_Click(object sender, EventArgs e)    
{
    try
    {
        string strPONumber = "";
        foreach (GridViewRow gvr in gvCanadaOrders.Rows)
        {
            if (((CheckBox)gvr.FindControl("cbPONumber")).Checked == true)
            {
                string strRec_ID = gvCanadaOrders.DataKeys[gvr.RowIndex].Value.ToString();

                //Update table here, diable inactive field;
                SqlConnection con = new SqlConnection(strConn);
                string sqlCanadaOrdersUpdate = "usp_CanadaOrders_Close";
                SqlCommand cmdCanadaOrdersUpdate = new SqlCommand(sqlCanadaOrdersUpdate, con);

                cmdCanadaOrdersUpdate.CommandType = CommandType.StoredProcedure;

                cmdCanadaOrdersUpdate.Parameters.Add(new SqlParameter("@rec_ID", SqlDbType.VarChar, 50));
                cmdCanadaOrdersUpdate.Parameters["@rec_ID"].Value = strRec_ID;

                cmdCanadaOrdersUpdate.Parameters.Add(new SqlParameter("@usr_id", SqlDbType.VarChar, 50));
                cmdCanadaOrdersUpdate.Parameters["@usr_id"].Value = User.Identity.Name.Substring(User.Identity.Name.Length - 7);

                con.Open();

                SqlDataAdapter sqladaCanadaOrdersUpdate = new SqlDataAdapter(cmdCanadaOrdersUpdate);
                cmdCanadaOrdersUpdate.ExecuteNonQuery();
            }
            ClientScript.RegisterStartupScript(GetType(), "alert", "alert('Purchase Order " + strPONumber + " has been disabled.');", true);
        }
    }

The code for gridview databoundrow is:

void gvCanadaOrders_RowDataBound(Object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
        // Display the company name in italics.
        e.Row.Cells[1].Text = "<i>" + e.Row.Cells[1].Text + "</i>";
    }
}
  • 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-15T16:51:22+00:00Added an answer on May 15, 2026 at 4:51 pm

    Hook in to the RowDataBound event of the GridView. From there, you can cast the DataItem to your record type. A test for the flag then lets you modify the row controls.

    I have this code in VB.net and did a quick conversion per your C# tag, so please forgive any errors.

    void myGridView_RowDataBound(Object sender, GridViewRowEventArgs e) {
        if (e.Row.RowType == DataControlRowType.DataRow) {
            MyObject myObj = (myObj)e.Row.DataItem;
            if (myObj.flag) {
                CheckBox cb = (CheckBox)e.Row.FindControl("myCheckBox");
                cb.Enabled=false;
            }
        }
    }
    

    EDIT: Per your edit to the question, you do not have OnRowDataBound in your markup. You would need to add OnRowDataBound=”gvCanadaOrders_RowDataBound”. It works the same way you’ve gon OnPageIndexChanging.

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

Sidebar

Related Questions

For example, Lets say that I have a gridview column which has important controls,
I have a gridview which contains few Template columns, In the first Template column
I have a gridview which contains a checkbox column and also uses pagination. When
I have a GridView which is programatically filled from the DB (not a SqlDataSource
I have a GridView which is databound to an XML Datasource. For one of
I have a GridView in which each row has a custom view. The grid
I have a GridView to which I bind a dataTable that I manually created.
I have a GridView in which I want to embed a checkbox into the
Good Morning/Afternoon all, I have a ASP:grid which displays current versions of Terms and
I have a gridview in which a specific column Date . I have set

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.