In actual development, a lot of information is often encountered. Due to the large number of fields, some data display controls such as gridview or radgrid are often used to display one row directly, with very poor results (you need to drag the scroll bar, ).
Therefore, we naturally want to use table to customize the template:
Let's start with the code and then analyze it.
<Asp: formview id = "fvbaseinfo" runat = "server" width = "100%" allowpaging = "true"
Onpageindexchanging = "fvbaseinfo_pageindexchanging">
<Itemtemplate>
<Table width = "100%" class = "mtable">
<Tr>
<TD colspan = "8" align = "center"> <font color = "red" size = "4"> basic information table of unpaid units </font> </TD>
</Tr>
<Tr>
<TD align = "right"> Approval Authority: </TD>
<TD align = "center">
<Asp: Label id = "label1" runat = "server" text = '<% # eval ("spjg1") %> 'forecolor = "buttonshadow"> </ASP: label>
</TD>
<TD align = "right"> Supervisory Authority: </TD>
<TD align = "center">
<Asp: Label id = "label2" runat = "server" text = '<% # eval ("jdgljg1") %> 'forecolor = "buttonshadow"> </ASP: label>
</TD>
<TD align = "right"> name of the water intake Authorizer: </TD>
<TD align = "center">
<Asp: Label id = "label3" runat = "server" text = '<% # eval ("qsqrmc") %> 'forecolor = "buttonshadow"> </ASP: label>
</TD>
<TD align = "right"> Legal Representative: </TD>
<TD align = "center">
<Asp: Label id = "label4" runat = "server" text = '<% # eval ("fddbr") %> 'forecolor = "buttonshadow"> </ASP: label>
</TD>
</Tr>
<Tr>
<TD align = "right"> title: </TD>
<TD align = "center">
<Asp: Label id = "label5" runat = "server" text = '<% # eval ("ZW") %> 'forecolor = "buttonshadow"> </ASP: label>
</TD>
<TD align = "right"> unit type: </TD>
<TD align = "center">
<Asp: Label id = "label6" runat = "server" text = '<% # eval ("dwlx") %> 'forecolor = "buttonshadow"> </ASP: label>
</TD>
<TD align = "right"> industry type: </TD>
<TD align = "center">
<Asp: Label id = "label7" runat = "server" text = '<% # eval ("hylb") %> 'forecolor = "buttonshadow"> </ASP: label>
</TD>
<TD align = "right"> water intake application date: </TD>
<TD align = "center">
<Asp: Label id = "label8" runat = "server" text = '<% # This. getsubstring (eval ("sqqsqsrq "). tostring () %> 'forecolor = "buttonshadow"> </ASP: Label>
</TD>
</Tr>
<Tr>
<TD align = "right"> license validity period: </TD>
<TD align = "center">
<Asp: Label id = "label9" runat = "server" text = '<% # This. getsubstring (eval ("xkzyxq "). tostring () %> 'forecolor = "buttonshadow"> </ASP: Label>
</TD>
<TD align = "right"> Mailing address: </TD>
<TD align = "center">
<Asp: Label id = "label10" runat = "server" text = '<% # eval ("txdz") %> 'forecolor = "buttonshadow"> </ASP: label>
</TD>
<TD align = "right"> zip code: </TD>
<TD align = "center">
<Asp: Label id = "label11" runat = "server" text = '<% # eval ("yzbm") %> 'forecolor = "buttonshadow"> </ASP: label>
</TD>
<TD align = "right"> contact: </TD>
<TD align = "center">
<Asp: Label id = "label12" runat = "server" text = '<% # eval ("lxr") %> 'forecolor = "buttonshadow"> </ASP: label>
</TD>
</Tr>
<Tr>
<TD align = "right"> Department: </TD>
<TD align = "center">
<Asp: Label id = "label13" runat = "server" text = '<% # eval ("gzbm") %> 'forecolor = "buttonshadow"> </ASP: label>
</TD>
<TD align = "right"> title: </TD>
<TD align = "center">
<Asp: Label id = "label14" runat = "server" text = '<% # eval ("zwzc") %> 'forecolor = "buttonshadow"> </ASP: label>
</TD>
<TD align = "right"> contact number: </TD>
<TD align = "center">
<Asp: Label id = "label15" runat = "server" text = '<% # eval ("lxdh1") %> 'forecolor = "buttonshadow"> </ASP: label>
</TD>
<TD align = "right"> Email: </TD>
<TD align = "center">
<Asp: Label id = "label16" runat = "server" text = '<% # eval ("dzxx1") %> 'forecolor = "buttonshadow"> </ASP: label>
</TD>
</Tr>
</Table>
</Itemtemplate>
<Emptydatatemplate>
& Lt; table width = "100%" & gt;
<Tr>
<TD align = "center"> <font color = "red" size = "3"> no information </font> </TD>
</Tr>
</Table>
</Emptydatatemplate>
</ASP: formview>
The preceding table is placed in the template column in formview to display more field information and provide browsing. In this case, if a large amount of information is obtained, how does one implement paging?
...
Protected void page_load (Object sender, eventargs E)
{
If (! Ispostback)
{
Vsdatatable1 = new datatable (); // basic information of the unpaid Unit
}
}
.
.
.
Protected void btnquery_click (Object sender, eventargs E)
{
String strsql = "select * From qsxk_djb1 ";
Dm_water dm = new dm_water ();
Dataset DS = DM. getsql (strsql );
This. fvbaseinfo. datasource = Ds;
This. fvbaseinfo. databind ();
Viewstate ["wjfdwjbxx"] = Ds. Tables [0];
}
...
// Pagination of the formview Control
Protected void fvbaseinfo_pageindexchanging (Object sender, formviewpageeventargs E)
{
// Paging code
This. fvbaseinfo. datasource = vsdatatable1;
This. fvbaseinfo. pageindex = E. newpageindex;
This. fvbaseinfo. databind ();
}
...
/// <Summary>
/// Basic information table of the non-paid unit of the viewable stored in viewstate
/// </Summary>
Private datatable vsdatatable1
{
Get {return viewstate ["wjfdwjbxx"] As datatable ;}
Set {viewstate ["wjfdwjbxx"] = value ;}
}
...
/// <Summary>
/// Common binding materials
/// </Summary>
Private void pagedatabind ()
{
Fvbaseinfo. datasource = vsdatatable1;
Fvbaseinfo. databind ();
}
...
/// <Summary>
/// Add a page for binding materials
/// </Summary>
/// <Param name = "getpageindex"> new page index </param>
Private void pagedatabind (int32 getpageindex)
{
This. fvbaseinfo. datasource = vsdatatable1;
Fvbaseinfo. pageindex = getpageindex;
Fvbaseinfo. databind ();
}
The most important thing here is to use viewstate to save the data source information for pagination, as shown in the following address:
Http://hi.csdn.net/space-95339-do-album-picid-551779.html
This is just an implementation solution for able paging. If you have any problems, please let us know.