<asp:GridView ID="GridView1" runat="server" Font-Size="Small" Font-Bold="true" DataKeyNames="ID"
EnableViewState="true" OnRowCommand="GridView1_RowCommand" ShowFooter="true"
OnRowDataBound="GridView1_RowDataBound" OnSorting="GridView1_Sorting"
OnPageIndexChanging="GridView1_PageIndexChanging"
OnSelectedIndexChanged="GridView1_SelectedIndexChanged"
CssClass="gridview" Width="1024px" AutoGenerateColumns="False" RowStyle-HorizontalAlign="center"
AllowSorting="true" EmptyDataText="没有数据" AllowPaging="True" PageSize="20" BorderColor="#93BEE2"
BorderWidth="1px" PagerStyle-HorizontalAlign="Right">
<HeaderStyle BackColor="#507CD1" Font-Size="9pt" Font-Bold="True" ForeColor="White" HorizontalAlign="Center" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" Font-Size="X-Small" HorizontalAlign="Center" />
<EditRowStyle BackColor="#2461BF" />
<AlternatingRowStyle BackColor="#ffffff" />
<Columns>
<asp:TemplateField HeaderText="序号" SortExpression="ID" >
<ItemTemplate>
<asp:LinkButton ID="LinkButton1" CommandName="Select" CommandArgument='<%#Eval("ID") %>' Font-Size="xx-Small" Width="60px" runat="Server" Text='<%# Eval("ID")%>' OnClick="lnkbtnGvEdit_Click"> <%# Eval("ID")%> </asp:LinkButton> </ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="ShortName" HeaderText="客户简称"
ItemStyle-HorizontalAlign="Left" ItemStyle-Width="7%" ItemStyle-Font-Size="X-Small" />
<asp:BoundField DataField="Name" HeaderText="客户全称"
ItemStyle-HorizontalAlign="Left" ItemStyle-Width="7%" ItemStyle-Font-Size="X-Small" />
<asp:BoundField DataField="Type" HeaderText="发票抬头" ItemStyle-HorizontalAlign="Left"
ItemStyle-Width="7%" ItemStyle-Font-Size="X-Small" />
<asp:BoundField DataField="sale" HeaderText="销售员" ItemStyle-HorizontalAlign="Left"
ItemStyle-Width="7%" ItemStyle-Font-Size="X-Small" />
<asp:BoundField DataField="clientservice" HeaderText="客服" ItemStyle-HorizontalAlign="Left"
ItemStyle-Width="4%" ItemStyle-Font-Size="X-Small" />
<asp:BoundField DataField="stat" HeaderText="结算员" ItemStyle-HorizontalAlign="Left"
ItemStyle-Width="6%" ItemStyle-Font-Size="X-Small" />
<asp:BoundField DataField="PayPerson" HeaderText="结算联系人" ItemStyle-HorizontalAlign="Left"
ItemStyle-Width="8.5%" ItemStyle-Font-Size="X-Small" />
<asp:BoundField DataField="remarks" HeaderText="客户备注" ItemStyle-HorizontalAlign="Left"
ItemStyle-Width="8%" ItemStyle-Font-Size="X-Small" />
<asp:BoundField DataField="ContactPerson" HeaderText="客户联系人" ItemStyle-HorizontalAlign="Left"
ItemStyle-Width="8.5%" ItemStyle-Font-Size="X-Small" />
<asp:BoundField DataField="Tel" HeaderText="客户电话" ItemStyle-HorizontalAlign="Left"
ItemStyle-Width="9.5%" ItemStyle-Font-Size="X-Small" />
<asp:BoundField DataField="Mobil" HeaderText="客户手机" ItemStyle-HorizontalAlign="Left"
ItemStyle-Width="9.5%" ItemStyle-Font-Size="X-Small" />
<asp:BoundField DataField="Fax" HeaderText="客户传真" ItemStyle-HorizontalAlign="Left"
ItemStyle-Width="9.5%" ItemStyle-Font-Size="X-Small" />
<asp:BoundField DataField="CLIENTNotes" HeaderText="客户对账单备注" ItemStyle-HorizontalAlign="Left"
ItemStyle-Width="20%" ItemStyle-Font-Size="X-Small" />
<asp:TemplateField HeaderText="编辑" HeaderStyle-Width="3%">
<HeaderTemplate>
</HeaderTemplate>
<ItemTemplate>
<%--<asp:CheckBox ID="chk" runat="server" />--%>
<asp:LinkButton ID="lnkbtnGvEdit" CssClass="lnkbtn" runat="server" CommandArgument='<%#Eval("ID") %>' Width="30px" Font-Size="X-Small" OnClick="lnkbtnGvEdit_Click">编辑</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<RowStyle HorizontalAlign="Center" Height="25px" BackColor="#EFF3FB" />
<EmptyDataRowStyle ForeColor="Red" HorizontalAlign="Center" />
<pagertemplate>
<table width="100%">
<tr>
<td style="text-align:right">
第<asp:Label id="lblPageIndex" runat="server" text='<%# ((System.Web.UI.WebControls.GridView)Container.Parent.Parent).PageIndex + 1 %>' />页
共/<asp:Label id="lblPageCount" runat="server" text='<%# ((System.Web.UI.WebControls.GridView)Container.Parent.Parent).PageCount %>' />页
<asp:linkbutton id="btnFirst" runat="server" causesvalidation="False" commandargument="First" commandname="Page" text="首页" />
<asp:linkbutton id="btnPrev" runat="server" causesvalidation="False" commandargument="Prev" commandname="Page" text="上一页" />
<asp:linkbutton id="btnNext" runat="server" causesvalidation="False" commandargument="Next" commandname="Page" text="下一页" />
<asp:linkbutton id="btnLast" runat="server" causesvalidation="False" commandargument="Last" commandname="Page" text="尾页" />
<asp:textbox id="txtNewPageIndex" runat="server" width="20px" text='<%# ((System.Web.UI.WebControls.GridView)Container.Parent.Parent).PageIndex + 1 %>' />
<asp:linkbutton id="btnGo" runat="server" causesvalidation="False" commandargument="-1" commandname="Page" text="跳转" />
本页<asp:Label ID="lblCount" runat="server" text='<%# GridView1.Rows.Count %>'/>条
</td>
</tr>
</table>
</pagertemplate>
</asp:GridView>
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
//GridView1.PageIndex = e.NewPageIndex;
GridView GridView1 = sender as GridView; // refer to the GridView
int newPageIndex = 0;
if (-2 == e.NewPageIndex)
{
TextBox txtNewPageIndex = null;// when click the "GO" Button
//GridViewRow pagerRow = GridView1.Controls[0].Controls[GridView1.Controls[0].Controls.Count - 1] as GridViewRow; // refer to PagerTemplate
GridViewRow pagerRow = GridView1.BottomPagerRow; //BottomPagerRow ,TopPagerRow,HeaderRow,FooterRow
if (null != pagerRow)
{
txtNewPageIndex = pagerRow.FindControl("txtNewPageIndex") as TextBox; // refer to the TextBox with the NewPageIndex value
}
if (null != txtNewPageIndex)
{
newPageIndex = int.Parse(txtNewPageIndex.Text) - 1; // get the NewPageIndex
}
}
else
{
newPageIndex = e.NewPageIndex;// when click the first, last, previous and next Button
}
newPageIndex = newPageIndex < 0 ? 0 : newPageIndex;// check to prevent form the NewPageIndex out of the range
newPageIndex = newPageIndex >= GridView1.PageCount ? GridView1.PageCount - 1 : newPageIndex;
GridView1.PageIndex = newPageIndex;// specify the NewPageIndex
dataBind();
}
public void GridView1_RowCommand(Object sender, EventArgs e)
{
if (!IsPostBack)
{
GridViewRow pagerRow = GridView1.BottomPagerRow;
TextBox pageList = (TextBox)pagerRow.FindControl("txtNewPageIndex");
GridView1.PageIndex = int.Parse(pageList.Text) - 1;// SelectedIndex;
dataBind();
}
}