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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T08:18:44+00:00 2026-06-03T08:18:44+00:00

I have a gridview with a column of asp buttons that I toggle the

  • 0

I have a gridview with a column of asp buttons that I toggle the text using javascript as follws:

function btnBuyToggle(objRef) 
{ 
    var row = objRef.parentNode.parentNode;
    var rowIndex = row.rowIndex;
    if (objRef.value == "ADD")
    {
        objRef.value = "REMOVE";
        $("#" + objRef.id).parent().parent().css("color", "#800080").css("font-style", "italic").css("background-color", "#F5FA61");
    } 
    else 
    {
      objRef.value = "ADD";
    }
}

Now I have added another gridview column of hidden checkboxes which I want to use for passing the toggled button instances back to the code behind on another button click event. So, what I need to do is modify the above script (JQuery is fine) to set the checkbox on the same row being toggled (checked for ADD button text values, and unchecked for the REMOVE button text values.

Here are my gridview fields:

<asp:TemplateField HeaderText="Prior <br /> Downld" HeaderStyle-ForeColor="White" > 
    <ItemTemplate >
       <asp:Button id="btnBuy" runat="server" OnClientClick="btnBuyToggle(this); return false;"
             Text="ADD" CssClass="buyButton" Visible="true" />
     </ItemTemplate>
    <HeaderStyle Width="7%" />
    <ItemStyle CssClass="sessionOrderDownloadItems" VerticalAlign="Middle" HorizontalAlign="Center" />
</asp:TemplateField>
<asp:TemplateField HeaderStyle-Width="0px" >
    <ItemTemplate>
        <asp:CheckBox Visible="False" Enabled="false" ID="buyCheckBoxHidden" runat="server"
             Checked='<%# Eval("SORD_SelectedForPurchaseFlag") %>' />
    </ItemTemplate>
    <HeaderStyle Width="0px" />
</asp:TemplateField>

Thank you,
Jim

Here is my attempted fixed script:

      function btnBuyToggle(objRef) 
          { 
            var $btn = $("#" + objRef.id);

            if (objRef.value == "ADD")
            {
                objRef.value = "REMOVE";
                $btn.closest('.myClass').prop("checked", true);
                $btn.parent().parent().css("color", "#800080").css("font-style", "italic").css("background-color", "#F5FA61");
            } else {
                objRef.value = "ADD";
                $btn.closest('.myClass').prop("checked", false);
                $btn.parent().parent().css("background-color", "#FFFFFF").css("color", "#191970").css("font-style", "normal");
            }
        }

And my modified checkbox markup:

<asp:TemplateField HeaderStyle-Width="0px" >
   <ItemTemplate>
     <asp:CheckBox style="display:block;" ID="buyCheckBoxHidden" runat="server" CssClass="myClass" Checked="false" />
   </ItemTemplate>
   <HeaderStyle Width="0px" />
</asp:TemplateField>

Thank you,
Jim

  • 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-06-03T08:18:46+00:00Added an answer on June 3, 2026 at 8:18 am

    Your first issue is that you have your checkbox set as visible="false". When you do this, the checkbox will not be visible to javascript. You need to change it be display:none. Secondly, you can use the jquery closest() method to grab the closest checkbox. To make this easier you should probably add a class to your checbox. Once you have found the checkbox, you can use the jquery prop() method to set the checked property to true or false.

    HTML:

    <asp:CheckBox runat="server" ID="buyCheckBoxHidden" Checked='<%# Eval("SORD_SelectedForPurchaseFlag") %>' style="display:none;" CssClass="class" />
    

    Javascript:

    function btnBuyToggle(objRef) 
    {
        var $row = $(objRef).closest('tr');
    
        if (objRef.value == "ADD")
        {
            objRef.value = "REMOVE";
            $row.find('.myClass').prop("checked", true);
            // OR $row.find('input[type=checkbox]').prop("checked", true);
            $row.css("color", "#800080").css("font-style", "italic").css("background-color", "#F5FA61");
        } else {
            objRef.value = "ADD";
            $row.find('.myClass').prop("checked", false);
            // OR $row.find('input[type=checkbox]').prop("checked", false);
            $row.css("background-color", "#FFFFFF").css("color", "#191970").css("font-style", "normal");
        }
    }​
    

    Here is an example jsfiddle.

    Edit:

    By the way jquery prop() is the recommended way of changing property values for jquery versions 1.6 and later. If you are using an earlier version of jquery, you will need to use the attr() method.

    Edit:

    Since it seems that the ASP.Net controls are removing your classes. FYI, ASP.Net controls have preset skins that can be found in your App_Themes folder and the theme you are using. Within the specific theme there is usually a Default.skin file that specifies what classes are on your controls by default. ASP.Net could possibly be removing your class when it creates the checkbox. You should search for the class that is added by ASP.net if you dont need to have your own class.

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

Sidebar

Related Questions

I have a asp gridview with button field column on that button click I
I have a radiobutton column in a gridview, inside many nested asp tables. I
For example, Lets say that I have a gridview column which has important controls,
I have a GridView. My GridView has a column that is contains an Options
I have a gridview in asp.net using vb 2005. on Protected Overrides Sub Rendersome
I have a Checkbox template column in a ASP.NET 3.5 GridView. Now the user
I have a GridView in ASP.net where I have a CheckBox column. The user
In a gridview, I have a column I use for images, using a template:
I am using ASP.NET to create a page with a GridView that is very
I have a ASP.NET GridView that uses template columns and user controls to allow

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.