How to extend ASP. NET DataGrid for multi-selection of data rows.

Source: Internet
Author: User

<Columns>

<Asp: templatecolumn>

<Headertemplate>

<Asp: checkbox id = "chkall"

<B> onclick = "javascript: selectallcheckboxes (this);" </B> runat = "server"

Autopostback = "false" tooltip = "select/deselect all"/>

</Headertemplate>

<Itemtemplate>

<Asp: checkbox id = "chkselect" <B> onclick = "javascript: highlightrow (this);" </B>

Runat = "server" <B> oncheckedchanged = "grdemployees_checkedchanged" </B>

Autopostback = "false"/>

</Itemtemplate>

</ASP: templatecolumn>

</Columns>

 

 

// ---------------------------------------------------------------
// select all the checkboxes (Hotmail style)
// -------------------------------------------------------------
function selectallcheckboxes (spanchk) {
// added as aspx uses span for checkbox
var oitem = spanchk. children;
var thebox = oitem. item (0)
xstate = thebox. checked;

Elm = thebox. Form. elements;

For (I = 0; I <Elm. length; I ++)

If (ELM [I]. type = "checkbox" & elm [I]. ID! = Thebox. ID)

{

// Elm [I]. Click ();

If (ELM [I]. Checked! = Xstate)

Elm [I]. Click ();

// Elm [I]. Checked = xstate;

}

}

//-------------------------------------------------------------

// ---- Select highlish rows when the checkboxes are selected

//

// Note: The colors are hardcoded, however you can use

// Registerclientscript Blocks Methods to use Grid's

// Itemtemplates and selecttemplates colors.

// For EX: grdemployees. itemstyle. backcolor or

// Grdemployees. selecteditemstyle. backcolor

//-------------------------------------------------------------

Function highlightrow (chkb ){

VaR oitem = chkb. Children;

Xstate = oitem. Item (0). checked;

If (xstate)

{Chkb. parentelement. parentelement. style. backgroundcolor = 'lightcoral ';

// Grdemployees. selecteditemstyle. backcolor

Chkb. parentelement. parentelement. style. Color = 'white ';

// Grdemployees. selecteditemstyle. forecolor

} Else

{Chkb. parentelement. parentelement. style. backgroundcolor = 'white ';

// Grdemployees. itemstyle. backcolor

Chkb. parentelement. parentelement. style. Color = 'black ';

// Grdemployees. itemstyle. forecolor

}

}

// -->

From http://www.codeproject.com/aspnet/Multi-select_Dataagrid.asp

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.