这次我们设计员工操作列表Custom.aspx和部门操作列表Departmant.aspx的设计.以及如何设计GridView的分页功能.
先调用BLL设计方法获取数据的List列表,转换成PagedDataSource,再设置PagedDataSource属性来实现分页功能.
先看Custom.aspx的设计:
<div style= "text-align: center" >
|
<asp:GridView ID= "gvCustom" DataKeyNames= "ID"
|
OnRowDeleting= "GridView_RowDeleting" runat= "server" CellPadding= "4"
|
ForeColor= "#333333" GridLines= "None" HorizontalAlign= "Center" Width= "98%"
|
CellSpacing= "1" AutoGenerateColumns= "False" >
|
<FooterStyle BackColor= "#507CD1" Font-Bold= "True" ForeColor= "White" />
|
<RowStyle BackColor= "#EFF3FB" HorizontalAlign= "Center" />
|
<EditRowStyle BackColor= "#2461BF" Font-Italic= "True" HorizontalAlign= "Center" VerticalAlign= "Middle" />
|
<SelectedRowStyle BackColor= "#D1DDF1" Font-Bold= "True" ForeColor= "#333333" />
|
<PagerStyle BackColor= "#2461BF" ForeColor= "White" HorizontalAlign= "Center" />
|
<HeaderStyle BackColor= "Silver" Font-Bold= "True" ForeColor= "White" Font-Size= "12px" HorizontalAlign= "Center" />
|
<AlternatingRowStyle BackColor= "White" />
|
<asp:BoundField DataField= "id" HeaderText= "ID" />
|
<asp:BoundField DataField= "ename" HeaderText= "帐户名" />
|
<asp:BoundField DataField= "cname" HeaderText= "姓名" />
|
<asp:BoundField DataField= "age" HeaderText= "年龄" />
|
<asp:BoundField DataField= "departname" HeaderText= "部门" />
|
<asp:HyperLinkField DataTextField= "id" DataTextFormatString= "修改"
|
HeaderText= "修改" DataNavigateUrlFields= "id" DataNavigateUrlFormatString= "Updatecustom.aspx?id={0}" />
|
<asp:TemplateField HeaderText= "删除" >
|
<asp:LinkButton ID= "LinkButton2" OnClientClick= "return confirm('您确认删除该记录吗?');" runat= "server" CommandName= "Delete" Font-Names= "宋体" Font-Strikeout= "False" Font-Underline= "False" ForeColor= "Black" >删除</asp:LinkButton>
|
<asp:Button ID= "btnAddUser" runat= "server" onclick= "btnAddUser_Click"
|
当前页码为:<asp:Label ID= "labPage" runat= "server" Text= "1" ></asp:Label>
|
总页码为:<asp:Label ID= "labBackPage" runat= "server" ></asp:Label>
|
<asp:LinkButton ID= "lnkbtnOne" runat= "server" OnClick= "lnkbtnOne_Click" >第一页</asp:LinkButton>
|
<asp:LinkButton ID= "lnkbtnUp" runat= "server" OnClick= "lnkbtnUp_Click" >上一页</asp:LinkButton>
|
<asp:LinkButton ID= "lnkbtnNext" runat= "server" OnClick= "lnkbtnNext_Click" >下一页</asp:LinkButton>
|
<asp:LinkButton ID= "lnkbtnBack" runat= "server" OnClick= "lnkbtnBack_Click" >最后一页</asp:LinkButton>
|
现来看下Custom.aspx.cs的设计:
记在先加上:
然后再:
public partial class Custom : PageBase
|
protected void Page_Load( object sender, EventArgs e)
|
customSystem CustomSystem = new customSystem();
|
List<custom> Customlist = new List<custom>();
|
Customlist = CustomSystem.GetCustom();
|
int curpage = Convert.ToInt32( this .labPage.Text);
|
PagedDataSource ps = new PagedDataSource();
|
ps.DataSource = Customlist;
|
ps.CurrentPageIndex = curpage - 1;
|
this .lnkbtnUp.Enabled = true ;
|
this .lnkbtnNext.Enabled = true ;
|
this .lnkbtnBack.Enabled = true ;
|
this .lnkbtnOne.Enabled = true ;
|
this .lnkbtnOne.Enabled = false ;
|
this .lnkbtnUp.Enabled = false ;
|
if (curpage == ps.PageCount)
|
this .lnkbtnNext.Enabled = false ;
|
this .lnkbtnBack.Enabled = false ;
|
this .labBackPage.Text = Convert.ToString(ps.PageCount);
|
gvCustom.DataSource = ps;
|
/// <param name="sender"></param>
|
/// <param name="e"></param>
|
protected void GridView_RowDeleting( object sender, GridViewDeleteEventArgs e)
|
int nid = Int32.Parse(gvCustom.DataKeys[e.RowIndex].Value.ToString());
|
customSystem CustomSystem = new customSystem();
|
CustomSystem.Deletecustom(nid);
|
/// <param name="sender"></param>
|
/// <param name="e"></param>
|
protected void lnkbtnOne_Click( object sender, EventArgs e)
|
/// <param name="sender"></param>
|
/// <param name="e"></param>
|
protected void lnkbtnUp_Click( object sender, EventArgs e)
|
this .labPage.Text = Convert.ToString(Convert.ToInt32( this .labPage.Text) - 1);
|
/// <param name="sender"></param>
|
/// <param name="e"></param>
|
protected void lnkbtnNext_Click( object sender, EventArgs e)
|
this .labPage.Text = Convert.ToString(Convert.ToInt32( this .labPage.Text) + 1);
|
/// <param name="sender"></param>
|
/// <param name="e"></param>
|
protected void lnkbtnBack_Click( object sender, EventArgs e)
|
this .labPage.Text = this .labBackPage.Text;
|
/// <param name="sender"></param>
|
/// <param name="e"></param>
|
protected void btnAddUser_Click( object sender, EventArgs e)
|
Response.Redirect( "Register.aspx" );
|
再来看下Departmant.aspx的设计:
<div style= "text-align: center" >
|
<asp:GridView ID= "GridView1" runat= "server" AutoGenerateColumns= "False" CellPadding= "4"
|
CellSpacing= "1" DataKeyNames= "ID" ForeColor= "#333333" GridLines= "None" HorizontalAlign= "Center"
|
OnRowDeleting= "GridView_RowDeleting" Width= "98%" >
|
<FooterStyle BackColor= "#507CD1" Font-Bold= "True" ForeColor= "White" />
|
<RowStyle BackColor= "#EFF3FB" HorizontalAlign= "Center" />
|
<EditRowStyle BackColor= "#2461BF" Font-Italic= "True" HorizontalAlign= "Center" VerticalAlign= "Middle" />
|
<SelectedRowStyle BackColor= "#D1DDF1" Font-Bold= "True" ForeColor= "#333333" />
|
<PagerStyle BackColor= "#2461BF" ForeColor= "White" HorizontalAlign= "Center" />
|
<HeaderStyle BackColor= "Silver" Font-Bold= "True" Font-Size= "12px" ForeColor= "White"
|
HorizontalAlign= "Center" />
|
<AlternatingRowStyle BackColor= "White" />
|
<asp:BoundField DataField= "id" HeaderText= "ID" />
|
<asp:BoundField DataField= "departname" HeaderText= "部门名称" />
|
<asp:BoundField DataField= "description" HeaderText= "部门描述" />
|
<asp:HyperLinkField DataNavigateUrlFields= "id" DataNavigateUrlFormatString= "Updatedepart.aspx?id={0}"
|
DataTextField= "id" DataTextFormatString= "修改" HeaderText= "修改" />
|
<asp:TemplateField HeaderText= "删除" >
|
<asp:LinkButton ID= "LinkButton2" runat= "server" CommandName= "Delete" Font-Names= "宋体"
|
Font-Strikeout= "False" Font-Underline= "False" ForeColor= "Black" OnClientClick= "return confirm('您确认删除该记录吗?');" >删除</asp:LinkButton>
|
<asp:Button ID= "btnAddDepartment" runat= "server" onclick= "btnAddDepartment_Click"
|
当前页码为:<asp:Label ID= "labPage" runat= "server" Text= "1" ></asp:Label> 总页码为:<asp:Label
|
ID= "labBackPage" runat= "server" ></asp:Label>
|
<asp:LinkButton ID= "lnkbtnOne" runat= "server" OnClick= "lnkbtnOne_Click" >第一页</asp:LinkButton>
|
<asp:LinkButton ID= "lnkbtnUp" runat= "server" OnClick= "lnkbtnUp_Click" >上一页</asp:LinkButton>
|
<asp:LinkButton ID= "lnkbtnNext" runat= "server" OnClick= "lnkbtnNext_Click" >下一页</asp:LinkButton>
|
<asp:LinkButton ID= "lnkbtnBack" runat= "server" OnClick= "lnkbtnBack_Click" >最后一页</asp:LinkButton>
|
然后再看Departmant.aspx.cs的设计:
也一样要先加上:
然后再:
public partial class departmant : PageBase
|
protected void Page_Load( object sender, EventArgs e)
|
departmentSystem DepartmentSystem = new departmentSystem();
|
List<department> Departmentlist = new List<department>();
|
Departmentlist = DepartmentSystem.GetDepartment();
|
int curpage = Convert.ToInt32( this .labPage.Text);
|
PagedDataSource ps = new PagedDataSource();
|
ps.DataSource = Departmentlist;
|
ps.CurrentPageIndex = curpage - 1;
|
this .lnkbtnUp.Enabled = true ;
|
this .lnkbtnNext.Enabled = true ;
|
this .lnkbtnBack.Enabled = true ;
|
this .lnkbtnOne.Enabled = true ;
|
this .lnkbtnOne.Enabled = false ;
|
this .lnkbtnUp.Enabled = false ;
|
if (curpage == ps.PageCount)
|
this .lnkbtnNext.Enabled = false ;
|
this .lnkbtnBack.Enabled = false ;
|
this .labBackPage.Text = Convert.ToString(ps.PageCount);
|
GridView1.DataSource = ps;
|
/// <param name="sender"></param>
|
/// <param name="e"></param>
|
protected void GridView_RowDeleting( object sender, GridViewDeleteEventArgs e)
|
int nid = Int32.Parse(GridView1.DataKeys[e.RowIndex].Value.ToString());
|
departmentSystem DepartmentSystem = new departmentSystem();
|
DepartmentSystem.Deletedepart(nid);
|
/// <param name="sender"></param>
|
/// <param name="e"></param>
|
protected void lnkbtnOne_Click( object sender, EventArgs e)
|
/// <param name="sender"></param>
|
/// <param name="e"></param>
|
protected void lnkbtnUp_Click( object sender, EventArgs e)
|
this .labPage.Text = Convert.ToString(Convert.ToInt32( this .labPage.Text) - 1);
|
/// <param name="sender"></param>
|
/// <param name="e"></param>
|
protected void lnkbtnNext_Click( object sender, EventArgs e)
|
this .labPage.Text = Convert.ToString(Convert.ToInt32( this .labPage.Text) + 1);
|
/// <param name="sender"></param>
|
/// <param name="e"></param>
|
protected void lnkbtnBack_Click( object sender, EventArgs e)
|
this .labPage.Text = this .labBackPage.Text;
|
/// <param name="sender"></param>
|
/// <param name="e"></param>
|
protected void btnAddDepartment_Click( object sender, EventArgs e)
|
Response.Redirect( "ADDdepart.aspx" );
|
到这里我们一个简单的三层架构的应用就设计完了,可能权限的设计有点薄弱,改天我再专门讲解下权限的设计,感谢大家一直以来对我关注和支持,同时也感谢大家的拍砖.