111,120
社区成员
发帖
与我相关
我的任务
分享
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" AllowPaging="True" Width="330px" Font-Size="Small"
BackColor="White" BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px" DataKeyNames="btID" PageSize="8"
CellPadding="3" OnRowEditing="GridView_Edit" OnRowCancelingEdit="GridView_Cancel" OnRowUpdating="GridView_Update"
OnRowDataBound="GridView_RowDataBound" OnRowDeleting="GridView_RowDeleting" OnDataBound = "GridView_DataBind">
<PagerTemplate>
<div id="main" align="left">
<div id="info">页次:<asp:Label ID="lblPageCurrent" runat="server" Text="1" ></asp:Label>
/<asp:Label ID="lblPageCount" runat="server" Text="1"></asp:Label> 共 <asp:Label ID="lblPageRow" runat="server" Text="1"
></asp:Label> 条记录
<br />
<asp:LinkButton ID="btnFirst" runat="server" CommandName="Pager" CommandArgument="First" OnCommand="NavigateToPage">[首页]</asp:LinkButton>
<asp:LinkButton ID="btnPrev" runat="server" CommandName="Pager" CommandArgument="Prev" OnCommand ="NavigateToPage">[前一页]</asp:LinkButton>
<asp:LinkButton ID="btnNext" runat="server" CommandName="Pager" CommandArgument="Next" OnCommand="NavigateToPage">[下一页]</asp:LinkButton>
<asp:LinkButton ID="btnLast" runat="server" CommandName="Pager" CommandArgument="Last" OnCommand="NavigateToPage">[尾页]</asp:LinkButton>
</div>
</PagerTemplate>
<FooterStyle BackColor="White" ForeColor="#000066" />
<RowStyle ForeColor="#000066" />
<PagerStyle BackColor="White" ForeColor="#000066" HorizontalAlign="Left" />
<SelectedRowStyle BackColor="#669999" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#006699" Font-Bold="True" ForeColor="White" />
<Columns>
<asp:BoundField DataField="btType" HeaderText="类型名称" ItemStyle-Width="150px">
<ItemStyle Width="150px"></ItemStyle>
</asp:BoundField>
<asp:CommandField HeaderText="编辑" ButtonType="image" EditImageUrl="~/Image/Edit.PNG" UpdateImageUrl="~/Image/Apply.PNG"
CancelImageUrl="~/Image/CANCEL.PNG" ShowEditButton="True" ItemStyle-Width="100px" ItemStyle-HorizontalAlign="Center">
<ItemStyle HorizontalAlign="Center" Width="100px"></ItemStyle>
</asp:CommandField>
<asp:CommandField HeaderText="删除" ButtonType="Image" DeleteImageUrl="~/Image/DELETE.PNG" ShowDeleteButton="True"
ItemStyle-Width="60px" ItemStyle-HorizontalAlign="Center">
<ItemStyle HorizontalAlign="Center" Width="60px"></ItemStyle>
</asp:CommandField>
</Columns>
</asp:GridView>
protected void GridView_Edit(object sender, GridViewEditEventArgs e)
{
this.GridView1.EditIndex = e.NewEditIndex;
Data_Binding();
}
protected void GridView_Cancel(object sender, GridViewCancelEditEventArgs e)
{
this.GridView1.EditIndex = -1;
Data_Binding();
}
protected void GridView_Update(object sender, GridViewUpdateEventArgs e)
{
//修改
}
protected void GridView_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
if (e.Row.RowState == DataControlRowState.Normal || e.Row.RowState == DataControlRowState.Alternate)
{
((ImageButton)e.Row.Cells[2].Controls[0]).Attributes["onclick"] = string.Format(JScript.DelStr, (e.Row.Cells[0].Text));
}
}
}
protected void GridView_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
//删除
JScript.Alert("该类型正在使用,不能删除!", Page);//弹出删除提示,这里不提示。。。。。。。
}
protected void NavigateToPage(object sender, CommandEventArgs e)
{
//控制转页
}
protected void GridView_DataBind(object sender, EventArgs e)
{
//分页控制
}
if(!isPostBack(){
})
[code=C#]
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using OASystem.Common;
using OASystem.Common.JS;
using OASystem.DALib;
public partial class BarMan_BarManType : System.Web.UI.Page
{
BarMng objBar = new BarMng();
protected void Page_Load(object sender, EventArgs e)
{
this.Title = "个同类型管理";
if (!IsPostBack)
{
Data_Binding();
this.TBbtType.Text = "";
this.TBbtType.Focus();
}
}
private void Data_Binding()
{
if (objBar.SelbtID_Max() != 0)
{
this.GridView1.DataSource = objBar.GetBargainType();
this.GridView1.DataBind();
}
}
protected void BtnAdd_Click(object sender, EventArgs e)
{
//保存
if (this.TBbtType.Text.ToString() == "")
{
JScript.Alert("类型名称不能为空!", Page);
this.TBbtType.Focus();
return;
}
if (objBar.ISUse_btType(this.TBbtType.Text.ToString()))
{
JScript.Alert("该类型已经存在!", Page);
this.TBbtType.Focus();
return;
}
try
{
int btid = objBar.SelbtID_Max();
objBar.InsertBargainType(btid + 1, this.TBbtType.Text.ToString());
Data_Binding();
this.TBbtType.Text = "";
this.TBbtType.Focus();
}
catch
{
JScript.Alert("类型添加失败!", Page);
this.TBbtType.Focus();
}
}
protected void GridView_Edit(object sender, GridViewEditEventArgs e)
{
this.GridView1.EditIndex = e.NewEditIndex;
Data_Binding();
}
protected void GridView_Cancel(object sender, GridViewCancelEditEventArgs e)
{
this.GridView1.EditIndex = -1;
Data_Binding();
}
protected void GridView_Update(object sender, GridViewUpdateEventArgs e)
{
//修改
int bttypeid = Convert.ToInt32(GridView1.DataKeys[e.RowIndex].Value.ToString());
TextBox bttype = this.GridView1.Rows[e.RowIndex].Cells[0].Controls[0] as TextBox;
try
{
objBar.UpdateBargainType(bttype.Text.ToString(), bttypeid);
}
catch
{
JScript.Alert("类型修改失败!", Page);
}
this.GridView1.EditIndex = -1;
Data_Binding();
}
protected void GridView_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
if (e.Row.RowState == DataControlRowState.Normal || e.Row.RowState == DataControlRowState.Alternate)
{
((ImageButton)e.Row.Cells[2].Controls[0]).Attributes["onclick"] = string.Format(JScript.DelStr, (e.Row.Cells[0].Text));
Label1.Text = "shanchiu";
//((ImageButton)原来使用的是linkbutton
}
}
}
protected void GridView_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
//删除
int bttypeid = Convert.ToInt32(GridView1.DataKeys[e.RowIndex].Value.ToString());
Label2.Text = "bushanchu";
JScript.Alert("该类型正在使用,不能删除!", Page);
//if (objBar.ISUse_btID(bttypeid))
//{
// JScript.Alert("该类型正在使用,不能删除!", Page);
// return;
//}
//try
//{
// objBar.DeleteBargainType(bttypeid);
// //JScript.ReURLToFrame("parent.mainframe", "itType.aspx");
//}
//catch
//{
// JScript.Alert("类型删除失败!", Page);
//}
//Data_Binding();
}
protected void NavigateToPage(object sender, CommandEventArgs e)
{
//控制转页
switch (e.CommandArgument.ToString())
{
case "First":
this.GridView1.PageIndex = 0;
break;
case "Prev":
if (this.GridView1.PageIndex > 0)
this.GridView1.PageIndex -= 1;
break;
case "Next":
if (this.GridView1.PageIndex < (this.GridView1.PageCount - 1))
this.GridView1.PageIndex += 1;
break;
case "Last":
this.GridView1.PageIndex = this.GridView1.PageCount - 1;
break;
}
Data_Binding();
}
protected void GridView_DataBind(object sender, EventArgs e)
{
GridView1.BottomPagerRow.Visible = true;//有数据时始终显示分页导航栏
GridViewRow pagerRow = GridView1.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.GridView1.PageIndex + 1).ToString();
}
if (lblCount != null)
{
lblCount.Text = this.GridView1.PageCount.ToString();
}
if (lblRow != null)
{
lblRow.Text = Convert.ToString(GridView1.Rows.Count);
}
if (this.GridView1.PageIndex == 0)
{
btnFirstTem.Enabled = false;
btnPrevTem.Enabled = false;
//只有一页,所有分页按钮不可用
if (this.GridView1.PageCount == 1)
{
btnNextTem.Enabled = false;
btnLastTem.Enabled = false;
}
}
else if (this.GridView1.PageIndex == (this.GridView1.PageCount - 1))
{
btnNextTem.Enabled = false;
btnLastTem.Enabled = false;
}
}
}
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="BarManType.aspx.cs" Inherits="BarMan_BarManType" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>无标题页</title>
<link href="BarManStyle.css" rel="stylesheet" type="text/css" />
</head>
<body>
<form id="form1" runat="server">
<div style="height: 374px; width: 683px;">
<table id="table1" cellpadding="1" cellspacing="0" width="330px" style="height:7px" border="0">
<tr><td height="10px"></td></tr>
<tr>
<td height="15px" align="left" style="font-size:smaller"><b>合同类型设置</b>
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
<asp:Label ID="Label2" runat="server" Text="Label"></asp:Label>
</td>
</tr>
</table>
<hr style="WIDTH: 330px; HEIGHT: 2px" size="2" align="left"/>
<table id="table2" style="width:330px; position: absolute;">
<tr>
<td height="20px" style="font-size:smaller">
类型名称:<asp:TextBox ID="TBbtType" runat="server" Width="102px"></asp:TextBox>
<asp:Button ID="BtnAdd" runat="server" CssClass="BnCss" Font-Size="9pt"
Height="22px" onclick="BtnAdd_Click" Text="添 加" Width="60px" />
</td>
</tr>
<tr>
<td>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" AllowPaging="True" Width="330px" Font-Size="Small"
BackColor="White" BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px" DataKeyNames="btID" PageSize="8"
CellPadding="3" OnRowEditing="GridView_Edit" OnRowCancelingEdit="GridView_Cancel" OnRowUpdating="GridView_Update"
OnRowDataBound="GridView_RowDataBound" OnRowDeleting="GridView_RowDeleting" OnDataBound = "GridView_DataBind">
<PagerTemplate>
<div id="main" align="left">
<div id="info">页次:<asp:Label ID="lblPageCurrent" runat="server" Text="1" ></asp:Label>
/<asp:Label ID="lblPageCount" runat="server" Text="1"></asp:Label> 共 <asp:Label ID="lblPageRow" runat="server" Text="1"
></asp:Label> 条记录
<br />
<asp:LinkButton ID="btnFirst" runat="server" CommandName="Pager" CommandArgument="First" OnCommand="NavigateToPage">[首页]</asp:LinkButton>
<asp:LinkButton ID="btnPrev" runat="server" CommandName="Pager" CommandArgument="Prev" OnCommand ="NavigateToPage">[前一页]</asp:LinkButton>
<asp:LinkButton ID="btnNext" runat="server" CommandName="Pager" CommandArgument="Next" OnCommand="NavigateToPage">[下一页]</asp:LinkButton>
<asp:LinkButton ID="btnLast" runat="server" CommandName="Pager" CommandArgument="Last" OnCommand="NavigateToPage">[尾页]</asp:LinkButton>
</div>
</PagerTemplate>
<FooterStyle BackColor="White" ForeColor="#000066" />
<RowStyle ForeColor="#000066" />
<PagerStyle BackColor="White" ForeColor="#000066" HorizontalAlign="Left" />
<SelectedRowStyle BackColor="#669999" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#006699" Font-Bold="True" ForeColor="White" />
<Columns>
<asp:BoundField DataField="btType" HeaderText="类型名称" ItemStyle-Width="150px">
<ItemStyle Width="150px"></ItemStyle>
</asp:BoundField>
<asp:CommandField HeaderText="编辑" ButtonType="image" EditImageUrl="~/Image/Edit.PNG" UpdateImageUrl="~/Image/Apply.PNG"
CancelImageUrl="~/Image/CANCEL.PNG" ShowEditButton="True" ItemStyle-Width="100px" ItemStyle-HorizontalAlign="Center">
<ItemStyle HorizontalAlign="Center" Width="100px"></ItemStyle>
</asp:CommandField>
<asp:CommandField HeaderText="删除" ButtonType="Image" DeleteImageUrl="~/Image/DELETE.PNG" ShowDeleteButton="True"
ItemStyle-Width="60px" ItemStyle-HorizontalAlign="Center">
<ItemStyle HorizontalAlign="Center" Width="60px"></ItemStyle>
</asp:CommandField>
</Columns>
</asp:GridView>
</td>
</tr>
</table>
</div>
</form>
</body>
</html>