页面


GridView 绑定:在中,有 <asp:BoundField/><asp:TemplateField><ItemTemplate>嵌套服务器控件 </ItemTemplate></asp:TemplateField>2种方式


<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Info_RegisteredPopulationList.aspx.cs"
Inherits="UI_Person_Info_RegisteredPopulationList" %> <%@ Register Assembly="WebPageContorl" Namespace="WebPageContorl" TagPrefix="cc1" %>
<!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>
</head>
<body>
<form id="form1" runat="server">
<div>
<div>
<asp:ImageButton ID="ibtnAdd" runat="server" ImageUrl="~/image/button_07.jpg" OnClick="ibtnAdd_Click" />
</div>
<asp:GridView ID="GridViewRegisteredPopulation" runat="server" AutoGenerateColumns="False"
DataSourceID="ObjectDataSource1" Width="100%"
OnRowDataBound="GridViewRegisteredPopulation_RowDataBound"
onrowcommand="GridViewRegisteredPopulation_RowCommand">
<Columns>
<asp:BoundField DataField="PopulationID" HeaderText="PopulationID" SortExpression="PopulationID"
Visible="False" />
<asp:BoundField DataField="Name" HeaderText="姓名" SortExpression="Name" />
<asp:BoundField DataField="PerIdNumber" HeaderText="PerIdNumber" SortExpression="PerIdNumber"
Visible="False" />
<asp:TemplateField HeaderText="性别">
<ItemTemplate>
<asp:Label ID="LblSex" Text='<%#Eval("Sex") %>' runat="server" />
</ItemTemplate>
</asp:TemplateField> <asp:TemplateField HeaderText="民族">
<ItemTemplate>
<asp:Label ID="LblNationality" Text='<%#Eval("Nationality") %>' runat="server" />
</ItemTemplate>
</asp:TemplateField> <asp:TemplateField HeaderText="婚姻状况">
<ItemTemplate>
<asp:Label ID="LblMaritalStatus" Text='<%#Eval("MaritalStatus") %>' runat="server" />
</ItemTemplate>
</asp:TemplateField> <asp:TemplateField HeaderText="宗教信仰">
<ItemTemplate>
<asp:Label ID="LblReligion" Text='<%#Eval("Religion") %>' runat="server" />
</ItemTemplate>
</asp:TemplateField> <asp:TemplateField HeaderText="职业类别">
<ItemTemplate>
<asp:Label ID="LblOccGenre" Text='<%#Eval("OccGenre") %>' runat="server" />
</ItemTemplate>
</asp:TemplateField> <asp:BoundField DataField="Occupation" HeaderText="职业" SortExpression="Occupation" />
<asp:BoundField DataField="UnitService" HeaderText="服务处所" SortExpression="UnitService" />
<asp:BoundField DataField="Contact" HeaderText="联系方式" SortExpression="Contact" />
<asp:TemplateField HeaderText="户籍地">
<ItemTemplate>
<asp:Label ID="LblLiveAddress" Text='<%#Eval("LiveAddress") %>' runat="server" />
</ItemTemplate>
</asp:TemplateField> <asp:TemplateField HeaderText="现在地">
<ItemTemplate>
<asp:Label ID="LblNowAddress" Text='<%#Eval("NowAddress") %>' runat="server" />
</ItemTemplate>
</asp:TemplateField> <asp:TemplateField HeaderText="与户主关系">
<ItemTemplate>
<asp:Label ID="LblMasterRelation" Text='<%#Eval("MasterRelation") %>' runat="server" />
</ItemTemplate>
</asp:TemplateField> <asp:BoundField DataField="MasterContact" HeaderText="户主联系方式" SortExpression="MasterContact" />
<asp:TemplateField HeaderText="操作">
<ItemTemplate>
<asp:ImageButton ID="ibtnModify" runat="server" ImageUrl="~/image/page_bj.png" CommandName="Modify"
CommandArgument='<%# Eval("PopulationID") %>' />&nbsp;
<asp:ImageButton ID="ibtnRemove" runat="server" OnClientClick="javascript:if(!confirm('确定删除此项?')){return false;}" ImageUrl="~/image/top_11.png" CommandName="Remove"
CommandArgument='<%# Eval("PopulationID") %>' />&nbsp;
<asp:ImageButton ID="ibtnSearch" runat="server" ImageUrl="~/image/page_ck.png" CommandName="Search"
CommandArgument='<%# Eval("PopulationID") %>' />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server" SelectMethod="GetPageList"
TypeName="BLL.Info_RegisteredPopulationBLL">
<SelectParameters>
<asp:Parameter DefaultValue="1" Name="pageIndex" Type="Int32" />
<asp:Parameter DefaultValue="12" Name="pageSize" Type="Int32" />
<asp:Parameter DefaultValue="" Direction="Output" Name="pageCount" Type="Int32" />
</SelectParameters>
</asp:ObjectDataSource>
</div>
<div id="mypage" runat="server">
<cc1:WebPager ID="WebPager2" runat="server" AlwaysShow="True" BorderStyle="None"
CssClass="paginator" CurrentPageButtonClass="cpb" CustomInfoHTML="当前第%CurrentPageIndex%页,共%PageCount%页/每页%PageSize%条,总记录数:%RecordCount%"
CustomInfoTextAlign="Right" FirstPageText="首页" HorizontalAlign="Left" LastPageText="尾页"
NextPageText="下一页" PrevPageText="上一页" ShowPageIndexBox="Never" Wrap="False" ShowCustomInfoSection="Left"
OnPageChanged="WebPager2_PageChanged" PageSize="12">
</cc1:WebPager>
</div>
<div style="display: none;">
<asp:Label ID="lPageIndex" runat="server" Text="0"></asp:Label>
<asp:Label ID="lPageSize" runat="server" Text="0"></asp:Label>
</div>
</form>
</body>
</html>
public partial class UI_Person_Info_RegisteredPopulationList : System.Web.UI.Page
{
//int pageIndex = 1, pageSize = 12, pageCount;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
SetPagerCounts();
}
}
public void SetPagerCounts()
{
WebPager2.RecordCount = Info_RegisteredPopulationBLL.GetTotalCount(); }
/// <summary>
/// 页码条变换事件方法 李可
/// </summary>
protected void WebPager2_PageChanged(object sender, EventArgs e)
{
bind();
} public void bind() {
lPageIndex.Text = (WebPager2.CurrentPageIndex).ToString();
int pageIndex = Convert.ToInt32(lPageIndex.Text);
lPageSize.Text = (WebPager2.PageSize).ToString();
int pageSize = Convert.ToInt32(lPageSize.Text); //复制SelectParameters
Parameter pageIndexPara = ObjectDataSource1.SelectParameters["pageIndex"];
Parameter pageSizePara = ObjectDataSource1.SelectParameters["pageSize"];
Parameter pageCountPara = ObjectDataSource1.SelectParameters["pageCount"];
//清除原有的SelectParameter
ObjectDataSource1.SelectParameters.Clear();
//重新给数据源赋值参数
pageIndexPara.DefaultValue = lPageIndex.Text;
pageSizePara.DefaultValue = lPageSize.Text;
//重新加入新的SelectParameter
ObjectDataSource1.SelectParameters.Add(pageIndexPara);
ObjectDataSource1.SelectParameters.Add(pageSizePara);
ObjectDataSource1.SelectParameters.Add(pageCountPara);
GridViewRegisteredPopulation.DataBind();
} protected void ibtnAdd_Click(object sender, ImageClickEventArgs e)
{
Response.Redirect("EditRegisteredPopulation.aspx?Id=0&Motion=" + Request.QueryString["Motion"]);
}
//数据绑定时触发的事件,区分repeator的ItemDataBound
protected void GridViewRegisteredPopulation_RowDataBound(object sender, GridViewRowEventArgs e)
{
//e.row排除其他模板类型生成的lblSex 对应的html 为null 未将引用~~实例
if (e.Row.RowType == DataControlRowType.DataRow)
{
/************性别*****************/
Label lblSex = e.Row.FindControl("lblSex") as Label;
if (!string.IsNullOrEmpty(lblSex.Text))
{
Dic_Sex ds = Dic_SexBLL.GetDic_Sex(lblSex.Text);
if (!string.IsNullOrEmpty(ds.Dic_Code))
lblSex.Text = ds.Dic_Name;
else
lblSex.Text = "未知";
}
/************民族*****************/
Label lblNationality = e.Row.FindControl("lblNationality") as Label;
if (!string.IsNullOrEmpty(lblSex.Text))
{
Dic_Sex ds = Dic_SexBLL.GetDic_Sex(lblNationality.Text);
if (!string.IsNullOrEmpty(ds.Dic_Code))
lblNationality.Text = ds.Dic_Name;
else
lblNationality.Text = "未知";
}
/************婚姻状况*****************/
Label lblMaritalStatus = e.Row.FindControl("lblMaritalStatus") as Label;
if (!string.IsNullOrEmpty(lblSex.Text))
{
Dic_Sex ds = Dic_SexBLL.GetDic_Sex(lblMaritalStatus.Text);
if (!string.IsNullOrEmpty(ds.Dic_Code))
lblMaritalStatus.Text = ds.Dic_Name;
else
lblMaritalStatus.Text = "未知";
}
/************宗教信仰*****************/
Label lblReligion = e.Row.FindControl("lblReligion") as Label;
if (!string.IsNullOrEmpty(lblSex.Text))
{
Dic_Sex ds = Dic_SexBLL.GetDic_Sex(lblReligion.Text);
if (!string.IsNullOrEmpty(ds.Dic_Code))
lblReligion.Text = ds.Dic_Name;
else
lblReligion.Text = "未知";
}
/************职业类别*****************/
Label lblOccGenre = e.Row.FindControl("lblOccGenre") as Label;
if (!string.IsNullOrEmpty(lblSex.Text))
{
Dic_Sex ds = Dic_SexBLL.GetDic_Sex(lblOccGenre.Text);
if (!string.IsNullOrEmpty(ds.Dic_Code))
lblOccGenre.Text = ds.Dic_Name;
else
lblOccGenre.Text = "未知";
}
/************户籍地*****************/
Label lblLiveAddress = e.Row.FindControl("lblLiveAddress") as Label;
if (!string.IsNullOrEmpty(lblSex.Text))
{
Dic_Sex ds = Dic_SexBLL.GetDic_Sex(lblLiveAddress.Text);
if (!string.IsNullOrEmpty(ds.Dic_Code))
lblLiveAddress.Text = ds.Dic_Name;
else
lblLiveAddress.Text = "未知";
}
/************现在地*****************/
Label lblNowAddress = e.Row.FindControl("lblNowAddress") as Label;
if (!string.IsNullOrEmpty(lblSex.Text))
{
Dic_Sex ds = Dic_SexBLL.GetDic_Sex(lblNowAddress.Text);
if (!string.IsNullOrEmpty(ds.Dic_Code))
lblNowAddress.Text = ds.Dic_Name;
else
lblNowAddress.Text = "未知";
}
/************与户主关系*****************/
Label LblMasterRelation = e.Row.FindControl("LblMasterRelation") as Label;
if (!string.IsNullOrEmpty(lblSex.Text))
{
Dic_Sex ds = Dic_SexBLL.GetDic_Sex(LblMasterRelation.Text);
if (!string.IsNullOrEmpty(ds.Dic_Code))
LblMasterRelation.Text = ds.Dic_Name;
else
LblMasterRelation.Text = "未知";
} }
} //区分repeator的ItemDataCommand
protected void GridViewRegisteredPopulation_RowCommand(object sender, GridViewCommandEventArgs e)
{
string commandName = e.CommandName;
long ID = Convert.ToInt64(e.CommandArgument);
switch (commandName)
{
case "Modify":
Response.Redirect("EditRegisteredPopulation.aspx?Id=" + ID + "&Motion=" + Request.QueryString["Motion"]);
break;
case "Remove":
Info_RegisteredPopulationBLL.DeleteRegister(ID);
//重新绑定
SetPagerCounts();
bind();
break;
case "Search":
Response.Redirect("EditRegisteredPopulation.aspx?Id=" + ID + "&Motion=" + Request.QueryString["Motion"]);
break;
default: break;
}
}
}

Asp.Net:GridView 编辑、删除、自定义分页以后备用的更多相关文章

  1. GridView编辑删除操作

    第一种:使用DataSource数据源中自带的编辑删除方法,这样的不经常使用,在这里就不加说明了. 另外一种:使用GridView的三种事件:GridView1_RowEditing(编辑).Grid ...

  2. GridView编辑删除

    A前台代码 <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="test.asp ...

  3. asp.net GridView增加删除功能

    protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)    {        string id ...

  4. GridView 编辑、删除 、分页

    类似代码都差不多,记录一下,便于以后查看使用. 前台页面: <asp:GridView ID="gdvList" runat="server" AutoG ...

  5. GridView自定义分页样式(上一页,下一页,到第几页)

    今天要为网站做一个文章列表,发现GridView的分页样式很难看,于是结合网上的例子,自己做了一个.不是很美观,不过还是很实用的,先看下效果吧,如图(1). 图(1)GridView分页效果 自定义G ...

  6. asp.net webform 自定义分页控件

    做web开发一直用到分页控件,自己也动手实现了个,使用用户自定义控件. 翻页后数据加载使用委托,将具体实现放在在使用分页控件的页面进行注册. 有图有真相,给个直观的认识: 自定义分页控件前台代码: & ...

  7. GridView总结二:GridView自带编辑删除更新

    GridView自带编辑删除更新逻辑很简单:操作完,重新绑定.总结总结,防止忘记... 效果图: 前台代码: <%@ Page Language="C#" AutoEvent ...

  8. asp gridview批量删除和全选

    本人新手刚学asp.net   全选和删除也是引用了他人的代码试了一试可以实现,感觉很好,就发了上来. 前台代码 <asp:GridView ID="GridView1" r ...

  9. Asp.net GridView 72般绝技

    快速预览:GridView无代码分页排序GridView选中,编辑,取消,删除GridView正反双向排序GridView和下拉菜单DropDownList结合GridView和CheckBox结合鼠 ...

随机推荐

  1. 20145221 《Java程序设计》实验报告二:Java面向对象程序设计

    20145221 <Java程序设计>实验报告二:Java面向对象程序设计 实验要求 初步掌握单元测试和TDD 理解并掌握面向对象三要素:封装.继承.多态 初步掌握UML建模 熟悉S.O. ...

  2. @RequestBody, @ResponseBody 注解详解

    简介: @RequestBody 作用: i) 该注解用于读取Request请求的body部分数据,使用系统默认配置的HttpMessageConverter进行解析,然后把相应的数据绑定到要返回的对 ...

  3. 无需u盘和光盘安装linux

    今天折腾linux引导的时候发现一个不用任何移动介质的linux安装方法,即直接在硬盘中启动安装系统. 1.首先下载一个easyBCD.进入“添加新条目”选项选择“NeoGrub”条目,然后选择“添加 ...

  4. canvas 在线画图

    canvas 在线画图 <!DOCTYPE html> <html lang="en"> <head> <meta charset=&qu ...

  5. 2-SAT问题及其算法

    原文地址:http://www.cppblog.com/MatoNo1/archive/2011/07/13/150766.aspx [2-SAT问题]现有一个由N个布尔值组成的序列A,给出一些限制关 ...

  6. Java线程面试题 Top 50

    转自:http://www.importnew.com/12773.html 不管你是新程序员还是老手,你一定在面试中遇到过有关线程的问题.Java语言一个重要的特点就是内置了对并发的支持,让Java ...

  7. ArcGIS for Android地图控件的5大常见操作

    GIS的开发中,什么时候都少不了地图操作.ArcGIS for Android中,地图组件就是MapView,MapView是基于Android中ViewGroup的一个类(参考),也是ArcGIS ...

  8. 关于zero pivot

    下面是运行一个adams/car模型出现的错误. ---- ERROR ----    The system matrix has a zero pivot for column 2142, whic ...

  9. 学习C# XmlSerializer 序列化反序列化XML

    类.变量常用头: [XmlRootAttribute]:对根节点的描述,在类声明中使用 如:下例的Html类 [XmlType]:对节点描述,在类声明中使用         如:下例的Head类 [X ...

  10. Java中的HashTable详解

    Hashtables提供了一个很有用的方法可以使应用程序的性能达到最佳. Hashtables(哈 希表)在计算机领域中已不 是一个新概念了.它们是用来加快计算机的处理速度的,用当今的标准来处理,速度 ...