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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T10:42:23+00:00 2026-05-15T10:42:23+00:00

I have a grid which has check boxes and when selecting the top chek

  • 0

I have a grid which has check boxes and when selecting the top chek box select all will select all the check box in gridview and would update .for this im using
for loop where it exceutes every time and this is taking lot of time cuase there are more thn 100 records in grid .

 try
{
    string StrOutputMessageDisplayDocReqCsu = string.Empty;
    string strid = string.Empty;
    string strflag = string.Empty;
    string strSelected = string.Empty;


    for (int j = 0; j < GdvDocReqMU.Rows.Count; j++)
    {
                    CheckBox Chkupdate = (CheckBox)GdvDocReqMU.Rows[j].Cells[1].FindControl("chkDR");
        if (Chkupdate != null)
        {
            if (Chkupdate.Checked)
            {
                strid = ((Label)GdvDocReqMU.Rows[j].FindControl("lblIDDocReqCsu")).Text;
                strflag = ((Label)GdvDocReqMU.Rows[j].FindControl("lblStatusDocReqCsu")).Text;                     
                cmd = new SqlCommand("sp_Update_v1", con);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue("@id", strSelected);
                cmd.Parameters.AddWithValue("@flag", DdlStatusDocReqMU.SelectedValue);
                cmd.Parameters.AddWithValue("@notes", txtnotesDocReqMU.Text);
                cmd.Parameters.AddWithValue("@user", strUseridDRAhk);
                cmd.Parameters.Add(new SqlParameter("@message", SqlDbType.VarChar, 100, ParameterDirection.Output, false, 0, 50, "message", DataRowVersion.Default, null));
                cmd.UpdatedRowSource = UpdateRowSource.OutputParameters;
                con.Open();
                cmd.ExecuteNonQuery();
                con.Close();

            }

        }
    }
    //}

    StrOutputMessageDisplayDocReqCsu += (string)cmd.Parameters["@message"].Value + "<br/>";
    lbldbmessDocReqAhk.Text += StrOutputMessageDisplayDocReqCsu + "<br>";
    GetgridDocReq();
 }
catch (Exception ex)
{
    lbldbmessDocReqAhk.Text = ex.Message.ToString();
}

can some please help me on this where i can capture all the id in one string n pass it to procedure

Thanks

  • 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-15T10:42:24+00:00Added an answer on May 15, 2026 at 10:42 am

    Here is how I’ve handled a similar situation (using jQuery to check the checkboxes):

    1. Add a single <asp:CheckBox Id="whatever" CssClass="chkAllSelector" ... to the column’s header
    2. Add CssClass="chkRowSelector" to your current checkboxes
    3. Add a footer template to this column’s footer with an update button or linkbutton.
    4. in the button’s onclick, perform your update.

    The ASP.NET checkbox control is weird because it wraps a span around the generated inputs.

    Here is the jQuery code I’ve used before:

    $('.chkAllSelector > input:checkbox').click(function() {
        $('.chkRowSelector > input:checkbox').each(
            function(){
                this.checked = $('.chkAllSelector > input:checkbox').attr('checked');
            }
        );
    });
    $('.chkRowSelector > input:checkbox').click(function() {
    if ($('.chkAllSelector > input:checkbox').is(':checked') && !($(this).is(':checked')))
         { $('.chkAllSelector > input:checkbox').removeAttr('checked'); }
     });
    

    As for your sql statement, since you’re using a stored procedure that is updating only one row at a time, you’re going to make a single call for every row. I’d suggest writing another stored procedure that takes an array of ids and sets the checked value. Note, you’ll have to do this call once for all checked values and once for all unchecked values. If your logic for checking/unchecking is pretty atomic, e.g. checking the box doesn’t change values in other tables within your stored procedure, it may be better to create a simple update statement and use it here. It’s hard to say without knowing the logic in your stored procedure.

    To avoid numerous headaches with the update scenario, you may also want to take a look at the SqlDataSource: http://quickstarts.asp.net/QuickStartv20/aspnet/doc/ctrlref/data/sqldatasource.aspx
    I use ObjectDataSource for nearly everything, because it handles insert/update/delete logic pretty nicely.

    Edit: To get a comma separated list of values:

    string idsCsv = GdvDocReqMU.Rows.Cast<GridViewRow>()
        .Where(x => ((CheckBox)x.FindControl("chkDR")).Checked)
        .Select(x => GdvDocReqMU.DataKeys[x.RowIndex].Value.ToString())
        .ToArray().Join(',');
    

    I just wrote that from scratch, so I’d be surprised if it works without a little tweaking, but that’s the general idea.

    For this to work, you have to set the gridview’s DataKeyNames=”Id” where “Id” is the id of the row being bound. For instance if you’re binding from sql and the column being bound to the gridview is “Customer_Id”, you’d have DataKeyNames=”Customer_Id”.

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

Sidebar

Related Questions

No related questions found

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.