• Home
  • About
  • BestBloggingIdeas
  • DotNetLearningSource
  • FORUM
  • Joblinks
  • Latest News
  • Policy
  • POSTS
  • SimplySqlServer.Com && SimplyAspDotNet.Com
  • Sitemap

Join Ours Forum

Asp.Net,C#,Ajax,Sql server,silverlight,Javascript codes exambles articles,Programming exambles

RSS Feed
  • Bounty Huge Roll [Amazon Frustration-Free Packaging]
  • XML Introduction to XML VHS Video Training, 1 hr., 32 minutes.
  • The Basic Overview of Windows Mobile Development Asp.Net C#
  • Overview of Sql server extended properties Asp.Net C#
  • How to Use Sql Server Extended properties using visual studio Asp.Net C#
  • Adobe Dreamweaver Templates Accelerate Web Development
  • Top Tips for Web Design Projects
  • How to Achieve a Good Web Design Structure
  • To Use Or Not To Use Website Templates
  • Five Tips to a Successful Website
  • Top 10 Articles,


    Silverlight Datagrid Select Update Delete Insert Asp.Net C#

    Differences Similarities Benefits Between Typed Datasets and Untyped Datasets asp.net c#

    Linq to Sql Introduction Entities Ado.Net C# SqlClasses Attributes Linq Mapping

    Linq Programming/How Linq Works?/Linq Implementation In Asp.Net C# Ado.Net

    Performing Developing Using Investigating Asp.Net 2.0 Ajax Application Development Asp.Net C#

    Hosting/Install Wcf Services in a Windows Service Asp.Net C#

    Connecting Silverlight to Wcf Asp.Net C#

    Silverlight Data Grid Data Binding WCF Asp.Net C#

    Invoking/Accessing/Calling WCF Service Without Adding/Creating Proxy/Reference Asp.Net C#

    Performing Doing Creating Insert Update Delete sql data Using Linq Database Asp.Net C#

    Bulk/MultiSelect GridView Rows using a Checkbox and JQuery Asp.Net C#

    Posted by james on March 23, 2011 Leave a comment (0) Go to comments

    Select Unselect GridView Rows

    To get started, create an ASP.NET website and drag a GridView control on the page. For this tutorial, I am using ID, Name and Salary columns, so I added three bound fields and one TemplateField that will contain the checkboxes in the header as well as in the individual row. Following is the complete HTML source for the GridView control.



    <asp:GridView ID=”GridView1″ runat=”server” Font-Size=”10pt”
       Font-Names=”Verdana” CellPadding=”4″ Width=”400px” GridLines=”None”
       ForeColor=”#333333″ AutoGenerateColumns=”false”>
       <RowStyle BackColor=”#EFF3FB” />
       <HeaderStyle BackColor=”#507CD1″ Font-Bold=”True” ForeColor=”White” />
       <AlternatingRowStyle BackColor=”White” />
       <Columns>
          <asp:TemplateField>
             <HeaderTemplate>
                <asp:CheckBox ID=”chkHeader” runat=”server” />
             </HeaderTemplate>
             <ItemTemplate>
                <asp:CheckBox ID=”chkRow” runat=”server” />
             </ItemTemplate>
          </asp:TemplateField>
          <asp:BoundField DataField=”ID” HeaderText=”ID” />
          <asp:BoundField DataField=”Name” HeaderText=”Name” />
          <asp:BoundField DataField=”Salary” HeaderText=”Salary” />
       </Columns>
    </asp:GridView>

    To keep this tutorial simple, I am not connecting my GridView with the database and showing some sample data in the GridView. Add the following code in the Page Load event of the page to add few rows of data.
    protected void Page_Load(object sender, EventArgs e)
    {
       if (!Page.IsPostBack)
       {
          LoadData();
       }
    }

    private void LoadData()
    {
       DataTable table = new DataTable();
       table.Columns.Add(“ID”, typeof(int));
       table.Columns.Add(“Name”, typeof(string));
       table.Columns.Add(“Salary”, typeof(decimal));

       for (int i = 1; i < 8; i++)
       {
          DataRow row = table.NewRow();
          row["ID"] = i;
          row["Name"] = “Name ” + i;
          row["Salary"] = 10000 * i;
          table.Rows.Add(row);
       }

       GridView1.DataSource = table;
       GridView1.DataBind();
    }

    Now we need only few lines of JQuery code to provide the functionality of selecting or deselecting rows using the checkbox added in the header of the GridView. Add the JQuery script file reference in the head element of the page.
    <script src=”scripts/jquery-1.4.3.min.js” type=”text/javascript”></script>
    Add the following JavaScript block inside the head element of the page.
    <script type=”text/javascript”>
       $(document).ready(function() {

          var headerCheckbox = $(‘#GridView1 > tbody > tr > th > input:checkbox’);

          headerCheckbox.click(function() {
             var headerChecked = $(this).attr(‘checked’);
             var rowCheckboxes = $(‘#GridView1 > tbody > tr > td > input:checkbox’);
             rowCheckboxes.attr(‘checked’, headerChecked);
          });

               
       });
    </script>

    The above code is using typical JQuery ready function to add some JQuery statements or code. The first line access the checkbox available in the header row of the GridView using JQuery selector.
    var headerCheckbox = $(‘#GridView1 > tbody > tr > th > input:checkbox’);
    Once we have the reference of header checkbox, we are using the click event function handler that will allow us to run some code every time user will click the header checkbox. Inside click event function handler, the first line stores the current state of the header checkbox in a headerChecked variable. The second line gets the reference of all the checkboxes in all the rows in GridView and then set their state to the same state as the header checkbox using JQuery attr function.



    headerCheckbox.click(function() {
       var headerChecked = $(this).attr(‘checked’);
       var rowCheckboxes = $(‘#GridView1 > tbody > tr > td > input:checkbox’);
       rowCheckboxes.attr(‘checked’, headerChecked);
    });


    Hope this helps,happy coding.

    ASP.NETCheckbox, Deselect, GridView, jQuery, Select, using
    ← Best/Easy Way to Resolving could not open a connection to SQL Server errors Asp.Net C#
    Controlling/Handling/Optimizing dataset processing time in SSRS reports Asp.Net C# Sql →

    Learn Easily Using Video Tutorials


    How to choose the right Java IDE – explained Eclipse NetBeans BlueJ

    Developing/Creating/Performing/Configuring Java Applications Using Eclipse IDE

    Step By Step Guide for Download/Install Configure Eclipse IDE for Java

    Editing data with the GridView control Asp.Net C#

    Registering/Configuring Web Controls globally in web.config file asp.net c#

    Registering/Configuring Web Controls globally in web.config file asp.net c#

    Best way to prepare asp.net Interview - Success Stories

    Download Important Questions and PPT's:

    Sql Server Important Questions Online free download

    Dotnet Important Questions Online free download

    Exploring Linq to Sql Process Flow

    Learn how to perform silverlight programming

    Learn OOPs concepts in better and well manner

    Learn Ajax in better and well manner

    Leave a Reply Cancel reply

    Your email address will not be published. Required fields are marked *

    *

    *


    You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

    Enter your email address:

    Delivered by FeedBurner

    • Recent Posts

      • Bounty Huge Roll [Amazon Frustration-Free Packaging]
      • XML Introduction to XML VHS Video Training, 1 hr., 32 minutes.
      • The Basic Overview of Windows Mobile Development Asp.Net C#
      • Overview of Sql server extended properties Asp.Net C#
      • How to Use Sql Server Extended properties using visual studio Asp.Net C#
    • Search by Tags!

      Application AspNet Basic between Black Bluetooth Build Business Collection Consultants Design Development Downloading effective Excel Experts Generics Implement Installing Interview Logic Management Microsoft Minutes Object Outlook Professional Programmer Programming Project Projects Questions Ready Select Server Services Silverlight Source Strings Studio Through using Visual Website Wordpress
    • Archives

      • August 2011
      • June 2011
      • May 2011
      • April 2011
      • March 2011
      • February 2011
      • December 2010
      • November 2010
      • October 2010
      • September 2010
      • August 2010
      • July 2010
      • June 2010
      • May 2010
      • April 2010
      • March 2010
      • February 2010
      • January 2010
      • December 2009
      • November 2009
      • October 2009
      • September 2009

    Copyright © 2012 NetProgrammingHelp.com

    Δ Top