Gridview CheckBox select and radio Version 2

Recommended for you: Get network issues from WhatsUp Gold. Not end users.

In the previous version of Insus.NET CheckBox GridView, has placed in the head, can Gridview the row select or whole operation cancelled.

Earlier edition:

This version, is to achieve Gridview Header CheckBox selection effect. If all records for non selection, change the CheckBox effect.

OK, Before demonstrating, first prepare a presentation of data and the environment.

First write an object:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

/// <summary>
/// Summary description for Soup
/// </summary>
namespace Insus.NET
{
    public class Soup
    {
        private string _Area;
        private string _Country;
        private string _SoupName;

        public string Area
        {
            get { return _Area; }
            set { _Area = value; }
        }
        public string Country
        {
            get { return _Country; }
            set { _Country = value; }
        }
        public string SoupName
        {
            get { return _SoupName; }
            set { _SoupName = value; }
        }

        public Soup()
        {
            //
            // TODO: Add constructor logic here
            //
        }
        public Soup(string area, string country, string soupName)
        {
            this._Area = area;
            this._Country = country;
            this._SoupName = soupName;
        }
    }
}

Insus.NET.Soup

As the object just written, filling the data:

 public List<Soup> GetAllData()
    {
        List<Soup> s = new List<Soup>();
        s.Add(new Soup("Asia", "China", "Apricot fragrant red dates of chicken soup"));
        s.Add(new Soup("Asia", "China", "The old fire soup"));
        s.Add(new Soup("Asia", "China", "Angelica Decoction"));
        s.Add(new Soup("Asia", "Thailand", "Tom Yum Goong soup"));
        s.Add(new Soup("Asia", "India", "Mulligatawny soup"));
        s.Add(new Soup("Asia", "China", "Steamed Abalone with Shark's Fin and Fish Maw in Broth"));
        s.Add(new Soup("Asia", "Japan", "Miso soup"));       
        s.Add(new Soup("America", "The United States of America", "Clam chowder"));
        s.Add(new Soup("Europe", "France", "Bouillabaisse"));
        s.Add(new Soup("Europe", "Spain", "Gazpacho"));
        s.Add(new Soup("Europe", "Russia", "Borsch"));
        return s;
    }

In the site, create a webpage, and a Gridview control to the webpage of (this operation you'll see), and then rewrite the GridVeiw control:

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false">
                <Columns>
                    <asp:TemplateField>
                        <HeaderTemplate>
                            <asp:CheckBox ID="CheckBox1" runat="server" ToolTip="Select all" onclick="SelectedAll(this);" />
                        </HeaderTemplate>
                        <ItemTemplate>
                            <asp:CheckBox ID="CheckBox2" runat="server" onclick="SelectedSingle(this);" />
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField>
                        <HeaderTemplate>
                            Area
                        </HeaderTemplate>
                        <ItemTemplate>
                            <%# Eval("Area") %>
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField>
                        <HeaderTemplate>
                            Country
                        </HeaderTemplate>
                        <ItemTemplate>
                            <%# Eval("Country") %>
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField>
                        <HeaderTemplate>
                            Soup Name
                        </HeaderTemplate>
                        <ItemTemplate>
                            <%# Eval("SoupName") %>
                        </ItemTemplate>
                    </asp:TemplateField>
                </Columns>
            </asp:GridView>

Go to.Aspx.cs to bind the GridView control data:

In the.Aspx GridView control, whether on Header or Row CheckBox, there is a Javascript method. Next, we complete the Javascript script:

 Below is the Head CheckBox:

Below is the Row CheckBox radio script:

You have a look, run

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download

Posted by Grover at November 14, 2013 - 5:12 AM