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 );
}