AllowPaging="True" OnDataBound="GV_jh_DataBound" OnPageIndexChanging="GV_jh_PageIndexChanging"
OnRowCommand="GV_jh_RowCommand" OnRowDataBound="GV_jh_RowDataBound">
<Columns>
<asp:BoundField HeaderText="本月计划" DataField="byjh">
<ItemStyle HorizontalAlign="Center" />
</asp:BoundField>
<asp:BoundField HeaderText="备注" DataField="bz">
<ItemStyle HorizontalAlign="Center" />
</asp:BoundField>
<asp:BoundField HeaderText="部门名称" DataField="depart">
<ItemStyle HorizontalAlign="Center" />
</asp:BoundField>
<asp:BoundField DataField="tjrname" HeaderText="提交人姓名">
<ItemStyle HorizontalAlign="Center" />
</asp:BoundField>
<asp:TemplateField HeaderText="状态">
<HeaderStyle Width="100" />
<ItemStyle HorizontalAlign="Center" />
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# cast(DataBinder.Eval(Container.DataItem,"state").ToString(),DataBinder.Eval(Container.DataItem,"isapproved"))%>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="审批">
<ItemStyle HorizontalAlign="Center" />
<HeaderStyle Width="50" />
<ItemTemplate>
<asp:LinkButton ID="lnk_sp" runat="server" CausesValidation="False" CommandName="sp"
CommandArgument='<%#Eval("id") %>'>审批</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<PagerTemplate>
<div id="main">
<div id="info">
页次:<asp:Label ID="lblPageCurrent" runat="server" Text="1" CssClass="txtInfo"></asp:Label>
/<asp:Label ID="lblPageCount" runat="server" Text="1"></asp:Label> 共 <asp:Label
ID="lblPageRow" runat="server" Text="1" CssClass="txtInfo"></asp:Label> 条记录
</div>
<div id="page">
<asp:LinkButton ID="btnFirst" runat="server" CssClass="link1" CommandName="Pager"
CommandArgument="First" OnCommand="NavigateToPage">[首页]</asp:LinkButton>
<asp:LinkButton ID="btnPrev" runat="server" CssClass="link1" CommandName="Pager"
CommandArgument="Prev" OnCommand="NavigateToPage">[前一页]</asp:LinkButton>
<asp:LinkButton ID="btnNext" runat="server" CssClass="link1" CommandName="Pager"
CommandArgument="Next" OnCommand="NavigateToPage">[下一页]</asp:LinkButton>
<asp:LinkButton ID="btnLast" runat="server" CssClass="link1" CommandName="Pager"
CommandArgument="Last" OnCommand="NavigateToPage">[尾页]</asp:LinkButton>
<asp:TextBox ID="txtNewPageIndex" SkinID="TxtSkin" runat="server" Width="20px" Text='<%# ((GridView)Container.Parent.Parent).PageIndex + 1 %>'
onpropertychange="if(/\D/g.test(value))value=value.replace(/\D/g,'')" />
<asp:LinkButton ID="btnGo" runat="server" CssClass="link1" CommandName="Pager" CommandArgument="Go"
OnCommand="NavigateToPage">GO</asp:LinkButton>
</div>
</div>
</PagerTemplate>
</asp:GridView>
protected void GV_jh_DataBound(object sender, EventArgs e)
{
if (rowCount > 0)
{
GridViewRow pagerRow = GV_jh.BottomPagerRow;
//获取Label实例,显示页次信息
Label lblCurrent = (Label)pagerRow.Cells[0].FindControl("lblPageCurrent");
Label lblCount = (Label)pagerRow.Cells[0].FindControl("lblPageCount");
Label lblRow = (Label)pagerRow.Cells[0].FindControl("lblPageRow");
//获取按钮实例,为了控制其是否可用
LinkButton btnFirstTem = (LinkButton)pagerRow.Cells[0].FindControl("btnFirst");
LinkButton btnPrevTem = (LinkButton)pagerRow.Cells[0].FindControl("btnPrev");
LinkButton btnNextTem = (LinkButton)pagerRow.Cells[0].FindControl("btnNext");
LinkButton btnLastTem = (LinkButton)pagerRow.Cells[0].FindControl("btnLast");
if (lblCurrent != null)
lblCurrent.Text = (this.GV_jh.PageIndex + 1).ToString();
if (lblCount != null)
lblCount.Text = this.GV_jh.PageCount.ToString();
if (lblRow != null)
lblRow.Text = rowCount.ToString();
if (this.GV_jh.PageIndex == 0)
{
btnFirstTem.Enabled = false;
btnPrevTem.Enabled = false;
//只有一页,所有分页按钮不可用
if (this.GV_jh.PageCount == 1)
{
btnNextTem.Enabled = false;
btnLastTem.Enabled = false;
}
}
else if (this.GV_jh.PageIndex == (this.GV_jh.PageCount - 1))
{
btnNextTem.Enabled = false;
btnLastTem.Enabled = false;
}
}
}
protected void NavigateToPage(object sender, CommandEventArgs e)
{
GridViewRow pagerRow = GV_jh.BottomPagerRow;
TextBox txtNewPageIndex = (TextBox)pagerRow.Cells[0].FindControl("txtNewPageIndex");
//控制转页
switch (e.CommandArgument.ToString())
{
case "First":
this.GV_jh.PageIndex = 0;
break;
case "Prev":
if (this.GV_jh.PageIndex > 0)
this.GV_jh.PageIndex -= 1;
break;
case "Next":
if (this.GV_jh.PageIndex < (this.GV_jh.PageCount - 1))
this.GV_jh.PageIndex += 1;
break;
case "Last":
this.GV_jh.PageIndex = this.GV_jh.PageCount - 1;
break;
case "Go":
if (txtNewPageIndex.Text.Trim() != "")
{
if (Convert.ToInt32(txtNewPageIndex.Text.Trim()) > 0 && Convert.ToInt32(txtNewPageIndex.Text.Trim()) < this.GV_jh.PageCount + 1)
this.GV_jh.PageIndex = Convert.ToInt32(txtNewPageIndex.Text.Trim()) - 1;
}
break;
}
BindView();
}
protected void GV_jh_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView theGrid = sender as GridView; // refer to the GridView
int newPageIndex = 0;
if (-2 == e.NewPageIndex)
{
// when click the "GO" Button
TextBox txtNewPageIndex = null;
GridViewRow pagerRow = theGrid.BottomPagerRow; //GridView较DataGrid提供了更多的API,获取分页块可以使用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
{ // when click the first, last, previous and next Button
newPageIndex = e.NewPageIndex;
}
// check to prevent form the NewPageIndex out of the range
newPageIndex = newPageIndex < 0 ? 0 : newPageIndex;
newPageIndex = newPageIndex >= theGrid.PageCount ? theGrid.PageCount - 1 : newPageIndex;
// specify the NewPageIndex
theGrid.PageIndex = newPageIndex;
}
public static void gvRowAddFun(ref GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
//if (themes == "BlueTheme")
//{
e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='E4E8EF'");
//}
//else if (themes == "GreenTheme")
//{
// e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='E4E8EF'");
//}
//else if (themes == "RedTheme")
//{
// e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='faebd7'");
//}
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=''");
}
}
protected void GV_jh_RowDataBound(object sender, GridViewRowEventArgs e)
{
gvRowAddFun(ref e);
e.Row.HorizontalAlign = HorizontalAlign.Center;
}
protected void GV_jh_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName.Equals("sp")) //查看审批 indexsp 是科长副科长的审批操作界面
{
string id = e.CommandArgument.ToString();
//Response.Redirect("view.aspx?id=" + id + "");
T_id = id;
ApprovePlan();
approvePlan.Visible = true;
}
}