- 浏览: 872204 次
- 性别:
- 来自: 青岛
文章分类
最新评论
-
chienchia:
请问下,第4步,vpn做了什么使数据包发送到真实网卡,而不会再 ...
如何使用Android系统自带的VPN服务框架 -
fangyafenqidai:
我只要选第二个就可以呢,怒需要选第一个。之后不会有啥问题。正常 ...
Android Studio 超级简单的打包生成apk -
michaelye1988:
不错,很棒!
getcachedir和getexternalcachedir的区别 -
whlei01:
文章棒棒哒
常用的AS3代码 -
whlei01:
很不错 之前打开及时600M的内存 ,现在打开只有300兆了 ...
flash builder内存不够的解决办法
ASP.NET3.5中包含了新的数据绑定控件--ListView,这是一个类似与repeater与gridview结合的控件,可以实现添加,删除功能,同时还可以像repeater一样灵活的控制页面的布局。该控件包含了很多新的模板,比如GroupTemplate等新增的模板,可以方便的分组显示数据。详细的大家可以去查MSDN文档。
我一直认为学习数据绑定控件从最简单的增删改查开始,可以对该控件有较深刻的理解,这样可以举一反三,在进行综合运用。今天这篇文章还是从最基本的数据操作开始,对ListView有个感性的认识。
页面源码:
这部分代码中有个重要的部分就是通过<LayoutTemplate>模板来设置控件的样式,布局,这也是新增的模板。在VS.NET2008的正式版本中,要正常运行页面必须在该模板中加入一个名为itemPlaceholder的PlaceHolder控件。要不会出现如下异常:
An item placeholder must be specified on ListView 'ListView1'. Specify an item placeholder by setting a control's ID property to "itemPlaceholder".
<ItemTemplate>模板用来绑定显示到页面上的数据, <EditItemTemplate>用来显示处于编辑状态的时候显示的数据,其他的可以以此类推。
与ListView还搭配的一起使用了新增的DataPager控件,这个主要是用于ListView控件的分页,是新增的分页空也,可以方便,高效的进行分页。
后台代码:
以前的edit_cancel事件在ListView控件中为item_cancel,在该事件中可以判断是取消编辑还是取消插入新的数据。大家可以看代码。本篇文章主要是对ListView控件一些基本的事件的运用。下一篇会继续深入的学习该控件。
我一直认为学习数据绑定控件从最简单的增删改查开始,可以对该控件有较深刻的理解,这样可以举一反三,在进行综合运用。今天这篇文章还是从最基本的数据操作开始,对ListView有个感性的认识。
页面源码:
<asp:ListView ID="ListView1" runat="server" OnSelectedIndexChanging="ListView1_SelectedIndexChanging" OnItemCommand="ListView1_ItemCommand" OnItemEditing="ListView1_ItemEditing" OnItemCanceling="ListView1_ItemCanceling" OnItemDataBound="ListView1_ItemDataBound" OnPagePropertiesChanging="ListView1_PagePropertiesChanging" OnItemInserting="ListView1_ItemInserting" OnItemUpdating="ListView1_ItemUpdating" OnSorting="ListView1_Sorting" EnableViewState="true" InsertItemPosition="LastItem" onitemdeleting="ListView1_ItemDeleting"> <LayoutTemplate> <asp:PlaceHolder ID="itemPlaceholder" runat="server"></asp:PlaceHolder> <p> <asp:DataPager ID="MyPage" runat="server" PageSize="6"> <Fields> <asp:NumericPagerField ButtonCount="10" PreviousPageText="<-- " NextPageText="-->" /> <%...-- <asp:NextPreviousPagerField ButtonType="Button" ShowFirstPageButton="true" ShowLastPageButton="true" ShowNextPageButton="true" ShowPreviousPageButton="true" />--%> </Fields> </asp:DataPager> </p> </LayoutTemplate> <ItemTemplate> <i> <%...#Eval("SupplierID")%></i> <p> <b> <%...#Eval("CompanyName")%></b></p> <p> <%...#Eval("ContactName")%></p> <p> <%...#Eval("Address")%></p> <p> <%...#Eval("City")%></p> <asp:Button ID="btnEdit" runat="server" Text="Edit" CommandName="Edit" /> <asp:Button ID="btnDelete" runat="server" Text="Delete" CommandName="Delete" /> <%...-- <asp:LinkButton ID="lbtnSort" runat="server" Text="Sort" CommandName="Sort" CommandArgument="CompanyName" ></asp:LinkButton>--%> </ItemTemplate> <EditItemTemplate> <asp:TextBox ID="txtMy" runat="server" Text='<%#bind("SupplierID") %>'></asp:TextBox> <asp:TextBox ID="TextBox1" runat="server" Text='<%#bind("CompanyName") %>'></asp:TextBox> <asp:TextBox ID="TextBox2" runat="server" Text='<%#bind("ContactName") %>'></asp:TextBox> <asp:TextBox ID="TextBox3" runat="server" Text='<%#bind("Address") %>'></asp:TextBox> <asp:TextBox ID="TextBox4" runat="server" Text='<%#bind("City") %>'></asp:TextBox> <asp:Button ID="btnUpdate" runat="server" Text="Update" CommandName="Update" /> <asp:Button ID="btnCancle" runat="server" Text="Cancle" CommandName="Cancel" /> </EditItemTemplate> <InsertItemTemplate> <asp:TextBox ID="txtMy" runat="server" Text='<%#bind("SupplierID") %>'></asp:TextBox> <asp:TextBox ID="TextBox1" runat="server" Text='<%#bind("CompanyName") %>'></asp:TextBox> <asp:TextBox ID="TextBox2" runat="server" Text='<%#bind("ContactName") %>'></asp:TextBox> <asp:TextBox ID="TextBox3" runat="server" Text='<%#bind("Address") %>'></asp:TextBox> <asp:TextBox ID="TextBox4" runat="server" Text='<%#bind("City") %>'></asp:TextBox> <asp:Button ID="btnUpdate" runat="server" Text="Insert" CommandName="Insert" /> <asp:Button ID="btnCancle" runat="server" Text="Cancle" CommandName="Cancel" /> </InsertItemTemplate> <ItemSeparatorTemplate> <div style="height: 0px; border-top: dashed 1px #ff0000"> </div> </ItemSeparatorTemplate> </asp:ListView>
这部分代码中有个重要的部分就是通过<LayoutTemplate>模板来设置控件的样式,布局,这也是新增的模板。在VS.NET2008的正式版本中,要正常运行页面必须在该模板中加入一个名为itemPlaceholder的PlaceHolder控件。要不会出现如下异常:
An item placeholder must be specified on ListView 'ListView1'. Specify an item placeholder by setting a control's ID property to "itemPlaceholder".
<ItemTemplate>模板用来绑定显示到页面上的数据, <EditItemTemplate>用来显示处于编辑状态的时候显示的数据,其他的可以以此类推。
与ListView还搭配的一起使用了新增的DataPager控件,这个主要是用于ListView控件的分页,是新增的分页空也,可以方便,高效的进行分页。
后台代码:
string ConStr = ConfigurationManager.ConnectionStrings["NorthwindConnectionString"].ConnectionString; protected void Page_Load(object sender, EventArgs e) ...{ if (!IsPostBack) ...{ ViewState["SupplierID"] = "SupplierID"; ViewState["Direction"] = "DESC"; BindListView(); } } private void BindListView() ...{ string QueryCon = "SELECT SupplierID,CompanyName,ContactName,Address,City FROM Suppliers"; SqlConnection NorthWindCon = new SqlConnection(ConStr); SqlDataAdapter NorthWindDa = new SqlDataAdapter(QueryCon, ConStr); DataSet Ds = new DataSet(); NorthWindDa.Fill(Ds, "Suppliers"); ListView1.DataKeyNames = new string[] ...{ "SupplierID" }; DataView Dv = Ds.Tables["Suppliers"].DefaultView; //排序表达式 string SortExpress = (string)ViewState["SupplierID"] + " " + (string)ViewState["Direction"]; Dv.Sort = SortExpress; //绑定数据源 //ListView1.DataSource = Ds.Tables["Suppliers"]; ListView1.DataSource = Dv; ListView1.DataBind(); } protected void ListView1_ItemEditing(object sender, ListViewEditEventArgs e) ...{ ListView1.EditIndex = e.NewEditIndex; BindListView(); } protected void ListView1_ItemDataBound(object sender, ListViewItemEventArgs e) ...{ if (e.Item.ItemType == ListViewItemType.DataItem) ...{ ((Button)e.Item.FindControl("btnDelete")).Attributes["onclick"] = "if(!confirm('你真的要删除这条记录么?'))return false;"; } } protected void ListView1_ItemCanceling(object sender, ListViewCancelEventArgs e) ...{ //取消编辑 if (e.CancelMode == ListViewCancelMode.CancelingEdit) ...{ //e.Cancel = true; ListView1.EditIndex = -1; BindListView(); ShowMessage("取消编辑"); } else if (e.CancelMode == ListViewCancelMode.CancelingInsert) ...{ //BindListView(); return; } } protected void ListView1_ItemInserting(object sender, ListViewInsertEventArgs e) ...{ ((TextBox)ListView1.InsertItem.FindControl("txtMy")).ReadOnly = true; string CompanyName = Server.HtmlEncode(((TextBox)ListView1.InsertItem.FindControl("TextBox1")).Text.ToString()); string ContactName = Server.HtmlEncode(((TextBox)ListView1.InsertItem.FindControl("TextBox2")).Text.ToString()); string Address = Server.HtmlEncode(((TextBox)ListView1.InsertItem.FindControl("TextBox3")).Text.ToString()); string City = Server.HtmlEncode(((TextBox)ListView1.InsertItem.FindControl("TextBox4")).Text.ToString()); string InsertQuery = "INSERT INTO Suppliers (CompanyName,ContactName,Address,City) VALUES ('" + CompanyName + "','" + ContactName + "','" + Address + "','" + City + "')"; SqlConnection InsertCon = new SqlConnection(ConStr); SqlCommand InsertCmd = new SqlCommand(InsertQuery, InsertCon); try ...{ InsertCon.Open(); InsertCmd.ExecuteNonQuery(); BindListView(); //将插入行显示到最后 ListView1.InsertItemPosition = InsertItemPosition.LastItem; } catch ...{ ShowMessage("插入新数据出错,请重新输入"); } finally ...{ InsertCon.Dispose(); InsertCmd.Dispose(); } } protected void ListView1_ItemUpdating(object sender, ListViewUpdateEventArgs e) ...{ string KeyId = ListView1.DataKeys[e.ItemIndex].Value.ToString(); //找到listview改行的数据集合 string CompanyName = Server.HtmlEncode(((TextBox)ListView1.Items[e.ItemIndex].FindControl("TextBox1")).Text.ToString()); string ContactName = Server.HtmlEncode(((TextBox)ListView1.Items[e.ItemIndex].FindControl("TextBox2")).Text.ToString()); string Address = Server.HtmlEncode(((TextBox)ListView1.Items[e.ItemIndex].FindControl("TextBox3")).Text.ToString()); string City = Server.HtmlEncode(((TextBox)ListView1.Items[e.ItemIndex].FindControl("TextBox4")).Text.ToString()); string UpdateStr = "UPDATE Suppliers SET CompanyName='" + CompanyName + "',ContactName='" + ContactName + "'," + "Address='" + Address + "',City='" + City + " 'WHERE SupplierID='" + KeyId + "' "; SqlConnection UpdateCon = new SqlConnection(ConStr); SqlCommand UpdateCmd = new SqlCommand(UpdateStr, UpdateCon); try ...{ UpdateCon.Open(); UpdateCmd.ExecuteNonQuery(); ListView1.EditIndex = -1; BindListView(); } catch ...{ ShowMessage("更新出错,请重新编辑"); } finally ...{ UpdateCon.Dispose(); UpdateCmd.Dispose(); } } protected void ListView1_Sorting(object sender, ListViewSortEventArgs e) ...{ if (ViewState["SupplierID"].ToString() == e.SortExpression) ...{ if (ViewState["Direction"].ToString() == "DESC") ...{ ViewState["Direction"] = "ASC"; } else ...{ ViewState["Direction"] = "DESC"; } } else ...{ ViewState["SupplierID"] = e.SortExpression; } BindListView(); } private void ShowMessage(string Message) ...{ Literal TxtMsg = new Literal(); TxtMsg.Text = "<script>alert('" + Message + "')</script>"; Page.Controls.Add(TxtMsg); } protected void ListView1_ItemDeleting(object sender, ListViewDeleteEventArgs e) ...{ string KeyID = ListView1.DataKeys[e.ItemIndex].Value.ToString(); string DeleteStr = "DELETE FROM Suppliers WHERE SupplierID='" + KeyID + "'"; SqlConnection DeleteCon = new SqlConnection(ConStr); SqlCommand DeleteCmd = new SqlCommand(DeleteStr, DeleteCon); try ...{ DeleteCon.Open(); DeleteCmd.ExecuteNonQuery(); BindListView(); ShowMessage("删除成功"); } catch ...{ ShowMessage("删除出错,请检查数据是否有关联"); } finally ...{ DeleteCon.Dispose(); DeleteCmd.Dispose(); } }
以前的edit_cancel事件在ListView控件中为item_cancel,在该事件中可以判断是取消编辑还是取消插入新的数据。大家可以看代码。本篇文章主要是对ListView控件一些基本的事件的运用。下一篇会继续深入的学习该控件。
发表评论
-
Request、Request.Form和Request.QueryString的区别
2012-08-13 14:46 1292Request、Request.Form和Request.Q ... -
大型软件公司.net面试题!一定得看(附答案)
2010-01-14 14:23 1633引用 1、答案 a=a+b; b=a-b; a=a ... -
.net面试整试题及参考答案【转】
2010-01-14 14:01 2243引用 一、ADO 与ADO.NET两 ... -
最新的.Net面试题及答案
2010-01-14 13:52 4129引用 最新的.Net面试题及答案 1.a=10,b=15,在不 ... -
NET面试题集
2010-01-12 16:48 2296引用 NET面试题集2009-08-2 ... -
如何记住密码?
2010-01-11 17:00 1248封装一个类,里面两个方法,一个是写,一个是读,直接调用即可 ... -
怎样在GridView中的DropDownList选项改变的时候获取GridView中的DataKeys.Value的二种方法:
2010-01-10 19:41 3409【1】 <asp:GridView ID="G ... -
Gridview中用删除一行的问题
2010-01-10 19:39 1570html代码如下: <asp:templatefie ... -
通过Visual studio 2005 中的web.sitemap实现OUTLOOK风格的系统菜单
2010-01-10 18:26 1997Visual Studio 开发工具提供的一些功能让开发变得更 ... -
Repeater分页
2010-01-10 18:06 2438private void Page_Load(ob ... -
单击头模板中的checkbox,实现datalist中所有chebox的全选和取消
2010-01-10 17:48 1803使用C#和javascript都可以实现,第二种更好一些, ... -
GridView 如何获取当前行的索引值
2010-01-10 16:10 7117引用 在用GridView控件时,我们经常会碰到获取当前行的索 ... -
DataGrid和DropDownList的一些配合以及使用css定制DataGrid
2010-01-10 16:06 1340引用 有的时候我们需要 (1)在编辑的时候用下拉框选择,并且默 ... -
[ASP] asp日期函数大全
2010-01-09 16:18 27351. Now 传回系统的日期及 ... -
ASP.net随机数应用实例
2010-01-09 16:15 1022大家可能都用过Chinaren的校友录,不久前它的留言簿上加 ... -
3种方式遍历Repeater中的CheckBox全选
2010-01-09 16:14 1721方式1 引用 1 foreach (Control c in ... -
[ASP.NET2.0]Repeater C# 分页用法
2010-01-09 16:03 2802二、Web.config配置 1 <ap ... -
(摘抄)为什么设置了DropDownList的AutoPostBack="True"还是不能触发SelectedIndexChanged事件?
2010-01-09 16:01 4216曾经遇到过这个问题,后来在LoveCherry的博客中找到了更 ...
相关推荐
Android+SQlite 简单的《学生信息管理系统》(实现基本增删改查) 此代码中还有与其相对应的apk文件(在SIMS/bin目录中),大家可先行放手机上看一下效果。 希望对初学者有一定的帮助。(本人自己编写)
DataList,Repeater,DetailsView,FormView,GridView,ListView的增删改查实例,用反射进行更换数据源,自己写的;是新手学习的好资料! DataListOpener.aspx DetailsViewOpener.aspx FormViewOpener.aspx ...
使用listview控件实现SQL数据的增删改查实例
目 录 (壹)SQLite数据库简介 (贰)数据库的创建 (叁)数据库的使用 ...ListView控件 常用数据适配器(Adapter) BaseAdapter SimpleAdapter ArrayAdapter 实战演练——Android应用市场 (代码
对sqlite的基本操作进行封装,可以自动生成拼接SQL语句,自动绑定数据并执行,简化了数据库的四项主要操作,减少代码量。 使用的大致步骤 ... 最后唠叨一句记着用完后关闭数据库,别的地方用时再打开
本文实例讲述了Android操作SQLite数据库(增、删、改、查、分页等)及ListView显示数据的方法。分享给大家供大家参考,具体如下: 由于刚接触android开发,故此想把学到的基础知识记录一下,以备查询,故此写的比较...
Android SQLite增删改查基本用法,通讯录实现 知识点包含: ListView控件的基本使用 SQLite数据库增删改查
该压缩包中包括一个android工程:db。主要是针对android中自带集成的SQLite数据库的操作。实现功能主要有:创建数据库、对数据库中数据的增删改查,以及事务在数据库中的应用,还有使用ListView显示数据库中的数据。
增、删、改时: //判断是否有选择项 if(this.listViewItem1.SelectedItems[0].Count>0) { //得到所选择的项 ListViewItem lvi = this.listViewItem1.SelectedItems[0]; //string id = lvi.SubItems[0].Text; //...
|--快捷方式增删查 |--手势识别器GestureDetector的用法 |--拍照之调用系统相机并显示及保存 |--拨打电话 |--按健之长按menu事件屏蔽 |--按健监听按返回健回桌面 |--搜索之调用系统Searchable的用法 |--数据库CURD...
【简介、创建、使用(增删改查、事务、实战演练)、数据显示控件(ListView、Adapter、实战演练)】 https://blog.csdn.net/weixin_44949135/article/details/105955663 Android 绿豆通讯录( SQLite数据库 + ListView...
利用Android Studio 2.2.3作为开发环境,采用代码建库的方式,制作了一个...用户可以对计划进行增删改查。双击删除,单击标题修改。待完成计划点击添加到已完成计划按钮,即可将计划添加到已完成中,数据库也随之改变。
一个C#简单的数据库操作技术,实现增删改查! 用到listview控件!
文件管理系统,支持csv文件的导入导出,数据的增删改查,mfc的listview、treeview控件的用法等
《C#全能速查宝典》共分为8章,分别介绍了C#语言基础、Windows窗体及常用控件、Windows高级控件、控件公共属性、方法及事件、数据库开发、文件、数据流与注册表、GDI+绘图技术和C#高级编程,共包含562个C#编程中常用...
界面简洁,功能全面,是一款非常强大的通讯录软件。除了包含数据库的增删改查,同时还含概treeView,listView,pictureBox等控件的使用方面的知识点
bmob示例-对象的增删改查.js caiji.js Calender.js canvas画正方形.js ceshi.js click控件获取坐标位置.js ColorMatrix处理图片↘颜色矩阵.js ColorMatrix颜色矩阵的用法.js common(1).js common.js ...
通过选择相应的专业来通过ListView控件来显示该专业所有学 生的成绩状况。还可以选择班级分班来查询 ② 成绩添加、删除及修改。通过双击相应同学的记录弹出窗体来设置成绩, 再通过点击刷新按钮来更新记录。 ...
实现数据库增、删、改、查的操作,使用CheckBox组件配合ListView控件实现点击Check选中的效果(可以多选),可以删除选中项和向选中对象发送短信(号码必须有效),内附使用说明。
服务端通过PHP语言编写,基于THINKPHP架构实现与客户端的数据通信,以及数据的增删改查操作。 客户端前台界面主要是采用activity加多fragment的方式进行功能页面的切换。每个fragment中通过ListView实现列表信息内容...