Tips for using DataGrid

Source: Internet
Author: User

When the mouse goes through a row, it is highlighted to increase the visual effect,CodeAs follows:
If (E. Item. itemtype = listitemtype. Item | E. Item. itemtype = listitemtype. alternatingitem)
{
E. Item. Attributes. Add ("onmouseover", "c = This. style. backgroundcolor; this. style. backgroundcolor = '#9ccbf7 '");
E. Item. Attributes. Add ("onmouseout", "This. style. backgroundcolor = C ");

}

The row color after the mouse goes through is #9ccbf7, And the mouse is moved back to the original color. Here, use C to save the original Top value first!

Put the above Code in the itemdatabind event.

DataGrid deletion confirmation

Private void maid (Object sender, system. Web. UI. webcontrols. datagriditemeventargs E)
{
Linkbutton MYDEL = (linkbutton) E. Item. findcontrol ("btndel ");
If (MYDEL! = NULL)
{
MYDEL. Attributes. Add ("onclick", "Return confirm ('Are you sure you want to delete it? ');");
}
}

DataGrid sorting

Private void datagrid1_sortcommand (Object source, system. Web. UI. webcontrols. datagridsortcommandeventargs E)
{
Dataset DS = new dataset ();
DS = dB. getdataset ("select * From mytab ");
Dataview DV = Ds. Tables [0]. defaultview;
DV. Sort = E. sortexpression;
Datagrid1. datasource = DV;
Datagrid1. databind ();

}

Bidirectional sorting...

If (viewstate ["order"] = NULL)
{
Viewstate ["order"] = "ASC ";
}
Else
{
If (viewstate ["order"]. tostring () = "ASC ")
{
Viewstate ["order"] = "DESC ";

}
Else
{
Viewstate ["order"] = "ASC ";
}

}< br> sqlconnection mycon = dB. creatcon ();
sqldataadapter da = new sqldataadapter ("select * from student order by studentid DESC", mycon);
dataset DS = new dataset ();
da. fill (DS, "tabnew");
dataview DV = Ds. tables [0]. defaultview;
DV. sort = E. sortexpression + "" + viewstate ["order"]. tostring ();
maid = DV;
maid. databind ();

Related Article

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.