LiisView的行单独页查看、编辑、新增(行数据量大不易查看时)

mac2022-06-30  17

好处:复杂的表不易查看、编辑、新增,将数据传到单独的页面进行查看、编辑、新增,信息详细易读清晰。

ListView页的配置:

分页一般用FromView,在FromView中获得控件时不用再e.Item....而是直接FromView1.FindControl("TextBox");

设置InsertItemPosition="None"因为不在本页编辑了,设置None后如果数据为空,则显示<EmptyDataTemplate>模板里面的内容,

删掉各种没用的模板,然后在每行添加“查看”“编辑”按钮(超链接)带着ID和action=(edit/view/addnew)重定向到ListViewUI页,

在DataSet中设定GetDataById查看单条数据方法,然后在ListViewUI页添加ObjectDataSource控件绑定数据选择GetDataById方法,

选择参数源为QueryString(请求字符串也就是地址栏),QueryStringField(传递的参数名)设置为Id

之后引入FormView控件(编辑单条数据的控件)绑定ObjectDataSource数据源,然后在页面Page_Load事件中根据Resope action=(edit/view/addnew)判断采用哪种模板.

添加,编辑后重定向到ListView页(ItemInserted/ItemUpdataed).

cs页代码:

using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; namespace ListView控件的绑定 { public partial class EditUI : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { if (Request["action"] == "edit") { FormView1.ChangeMode(FormViewMode.Edit); } else if (Request["action"] == "addnew") { FormView1.ChangeMode(FormViewMode.Insert); } else if (Request["action"] == "view") { FormView1.ChangeMode(FormViewMode.ReadOnly); } else { throw new Exception("action错误!"); } } } protected void FormView1_ItemInserted(object sender, FormViewInsertedEventArgs e) { Response.Redirect("ListViewUI.aspx"); } protected void FormView1_ItemUpdated(object sender, FormViewUpdatedEventArgs e) { Response.Redirect("ListViewUI.aspx"); } } }

 

在模板中巧用<asp:Literal>控件添加TextBox的jq显示日历事件(此方法IE6不兼容,浏览器问题)

<link href=""../css/ui-lightness/jquery-ui-1.8.2.custom.css" rel="stylesheet" type="text/css">

<script type="text/javascript" src="../js/jquery-1.4.2.js"></script>

<script type="text/javascript" src="../js/jquery-ui-1.8.2.custom.min.js"></script>

在模板中添加<asp:Literal>控件,然后在cs页把ItemCreate事件中

if (FormView1.ChangeMode == FormViewMode.Insert) {

Literal lit=(Literal)FindContorl("Literal1");

TextBox txtId=FindControl("TextBox1");

lit.Text=txtId.ClientId;

 }

<scritp type="text/javascript">

$('#<asp:Literal Id="litId"> runat="server"').datepicker();

</scritp>

转载于:https://www.cnblogs.com/blackHorseplan/p/3894368.html

相关资源:JAVA上百实例源码以及开源项目
最新回复(0)