Application of the gridview binding method and Selection Method

Source: Internet
Author: User
Private void gridviewbind ()
{
Gridview1.datasource = data source;
Gridview1.datakeynames = new string [] {"ID"}; // use an array to specify
Gridview1.databind ();
}

Some special effects in the gridview.
Protected void gridview1_rowdatabound (Object sender, gridviewroweventargs E)
{
If (E. Row. rowtype = datacontrolrowtype. datarow)
{
// Highlight the specified row
E. Row. Attributes. Add ("onmouseover", "color = This. style. backgroundcolor; this. style. backgroundcolor = '# fff000 '");
E. Row. Attributes. Add ("onmouseout", "This. style. backgroundcolor = color ;");
// Format the time
E. Row. cells [5]. Text = convert. todatetime (E. Row. cells [5]. Text). to1_datestring ();
// When you delete data from a specified row, a dialog box is displayed.
(Linkbutton) (E. Row. cells [8]. controls [0]). Attributes. Add ("onclick", "Return confirm ('whether to delete the data of the current row! ')");
// Display unused words...
// Stringformat. Out is a custom method, which is equal to substring ()
E. Row. cells [1]. Text = stringformat. Out (E. Row. cells [2]. Text, 7 );
E. Row. cells [2]. Text = stringformat. Out (E. Row. cells [2]. Text, 16 );
}
}

Apply the select button in the gridview
Protected void gridviewincluselectedindexchanging (Object sender, gridviewselecteventargs E)
{
String id = gridview1.datakeys [E. newselectedindex]. value. tostring ();
Response. Write ("<SCRIPT> window. Open ('detailleaguerinfo. aspx? Id = "+ ID +" ', '', 'rollbars') </SCRIPT> ");
Response. Write ("<SCRIPT> history. Go (-1) </SCRIPT> ");
}

If (E. Row. rowtype = datacontrolrowtype. datarow)
{
// Highlight the specified row
E. Row. Attributes. Add ("onmouseover", "color = This. style. backgroundcolor; this. style. backgroundcolor = '# fff000 '");
E. Row. Attributes. Add ("onmouseout", "This. style. backgroundcolor = color ;");
// Set the audit status and color.
If (E. Row. cells [5]. Text = "false ")
{
E. Row. cells [5]. Text = stringformat. Highlight ("not reviewed", true );
}
Else
{
E. Row. cells [5]. Text = stringformat. Highlight ("reviewed", false );
}
// Display unused words...
E. Row. cells [2]. Text = stringformat. Out (E. Row. cells [2]. Text, 18 );

}

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.