datagrid| Skills DataGrid Custom Paging navigation
Effect:
Let the DataGrid do this for its own paging
[1] [2] [3] [4] [5] [6]
private void Grid_itemcreated (object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if (E.item.itemtype==listitemtype.pager)
{
foreach (Control C in E.item.cells[0]. Controls)
{
if (c is Label)//Current page
{
Label lblpage= (label) C;
Lblpage. Forecolor= System.Drawing.ColorTranslator.FromHtml ("#e78a29"); #e78a29, #FF0000
Lblpage. Font.bold=true;
Lblpage. Text= "[<font color= #e78a29 ><b>" +lblpage. Text+ "</B></FONT>]";
((Label) c). ForeColor = System.Drawing.Color.Green;
Break
}
if (c is LinkButton)//links to other pages
{
LinkButton LinkButton = (LinkButton) C;
Linkbutton.text = "[" + linkbutton.text+ "]";
}
}
}
}
Automatic numbering in controls such as DataGrid:
To add a template column:
<asp:templatecolumn headertext= "No." >
<itemstyle horizontalalign= "Center" ></ItemStyle>
<ItemTemplate>
<asp:label runat= "Server" text= ' <%# dgcustomize.currentpageindex*dgcustomize.pagesize+ Dgcustomize.items.count+1%> ' >
</asp:Label>
</ItemTemplate>
</asp:TemplateColumn>
Create a complex header in a DataGrid
Method One: Use table to implement
<form id= "Form1" method= "POST" runat= "Server" >
<table id= "Table1" runat= "Server" cellspacing= "1" cellpadding= "2" width= "580" border= "1"
Bgcolor= "#cc6633" "bordercolor=" #cc9966 "style=" FONT-SIZE:9PT; border-bottom:0px ">
<TR align= "center" >
<TD colspan= "2" width= "380" style= "height:21px" ></TD>
<TD width= "colspan=" 2 "style=" height:21px "></TD>
</TR>
<TR align= "center" >
<TD width= "bgcolor=" "#66cc99" ><font face= "song Body" ></FONT></TD>
<TD width= "180" bgcolor= "white" ><font face= "song Body" ></FONT></TD>
<TD width= "160" bgcolor= "#99cccc" ></TD>
<TD width= "bgcolor=" "#009999" ></TD>
</TR>
</TABLE>
<asp:datagrid id= "DataGrid1" width= "580px" alternatingitemstyle-backcolor= "#6699ff" cellpadding= "2"
cellspacing= "1" borderwidth= "1" bordercolor= "#cc9966" font-size= "9pt" runat= "Server" showheader= "False"
autogeneratecolumns= "False" >
<Columns>
<asp:boundcolumn datafield= "Title" >
<itemstyle width= "200px" ></ItemStyle>
</asp:BoundColumn>
<asp:boundcolumn datafield= "CreateDate" >
<itemstyle width= "180px" ></ItemStyle>
</asp:BoundColumn>
<asp:boundcolumn datafield= "pid" >
<itemstyle width= "160px" ></ItemStyle>
</asp:BoundColumn>
<asp:boundcolumn datafield= "Hitcount" >
<itemstyle width= "40px" ></ItemStyle>
</asp:BoundColumn>
</Columns>
</asp:DataGrid>
</form>
Top of form
Bottom of form
Method Two: Dynamically generating a table header
To generate a double table header:
private void Grid_itemdatabound (object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if (E.item.itemtype = = Listitemtype.header)
{
E.item.cells[0]. ColumnSpan = 1;//This is the number of spanned columns in the first column
StringBuilder strtext=new StringBuilder ();
strtext. Append ("\\</td>");
strtext. Append ("<td colspan=4> Life Lighting </td>");
strtext. Append ("<td colspan=2> General lighting </td>");
strtext. Append ("<td colspan=2> industrial </td>");
strtext. Append ("<td colspan=2> Nong