Repeater控件的
http://blog.csdn.net/zhang_xinxiu/article/details/21872433
想起来,公司的aspx页面前台数据展示除了datagrid以为还有Repeater控件,现在温习温习这个控件
1:// 从一个数据项中获得相应的控件
TextBox txtTitle = (TextBox)e.Item.FindControl("txtTitle");
得记住这样获取值的方式,(控件类型)的转换
2:CheckBox chkInTheaters = (CheckBox)e.Item.FindControl("chkInTheaters");
<asp:Repeater ID="userRepeat" runat="server" OnItemCommand="userRepeat_ItemCommand" OnItemDataBound="userRepeat_ItemDataBound">
标红的是 Repeater控件命令事件
<ItemTemplate>
<tr>
<td><%#Eval("ID") %></td>
<td><%#Eval("Title") %></td>
<td><%#Eval("Cont") %></td>
<td><%#Eval("Keys") %></td>
<td><%#Eval("Des") %></td>
<td><%#Eval("AddTime") %></td>
<td>
<asp:LinkButton ID="LinkButton1" runat="server" CommandName="Del" CommandArgument='<%#Eval("ID") %>'>删除</asp:LinkButton>
<asp:LinkButton ID="LinkButton2" runat="server" CommandName="Update" CommandArgument='<%#Eval("ID") %>'>修改</asp:LinkButton>
<asp:Label ID="Label1" runat="server" Text='<%#Eval("NewID") %>' Visible="false"></asp:Label>
<asp:LinkButton ID="LinkButton1" runat="server" CssClass="btn btn82 btn_del" CommandName="del" OnClientClick="return confirm('要删除吗?')">删除</asp:LinkButton>
<asp:Label ID="Label2" runat="server" Text='<%#Eval("NewID") %>' Visible="false"></asp:Label>
<asp:LinkButton ID="LinkButton2" runat="server" CommandName="Update" CommandArgument='<%#Eval("NewID")%>'>修改</asp:LinkButton>
前台代码通过设置控件的CommandArgument属性来传递后台所需要判断的id号。
两种不同的颜色相互对应,当点击删除时,获取"Del"的指令 然后获取到要删除数据的ID值
if (e.CommandName == "Del")
{
//string strid = ((Label)e.Item.FindControl("Label1")).Text;
// int Id = Convert.ToInt32(strid);
int id = Convert.ToInt32(e.CommandArgument.ToString());
绑定数据:
- /// <summary>
- /// 将数据源绑定Repeater控件上
- /// </summary>
- private void DataBindToRepeater() {
- //使用using语句进行数据库连接
- using (SqlConnection sqlCon=new SqlConnection("server=.;database=MyBlog;uid=sa;pwd=1"))
- {
- sqlCon.Open(); //打开数据库连接
- SqlCommand sqlcom = new SqlCommand(); //创建数据库命令对象
- sqlcom.CommandText = "select * from match"; //为命令对象指定执行语句
- sqlcom.Connection = sqlCon; //为命令对象指定连接对象
- this.userRepeat.DataSource = sqlcom.ExecuteReader(); //为Repeater对象指定数据源
- this.userRepeat.DataBind(); //绑定数据源
- }
- }
- protected void userRepeat_ItemCommand(object source, RepeaterCommandEventArgs e)
- {
- //获取命令文本,判断发出的命令为何种类型,根据命令类型调用事件
- if (e.CommandName=="Edit") //编辑命令
- {
- id = int.Parse(e.CommandArgument.ToString()); //获取命令ID号
- }
- else if (e.CommandName=="Cancel") //取消更新命令
- {
- id = -1;
- }
- else if(e.CommandName=="Delete") //删除行内容命令
- {
- id = int.Parse(e.CommandArgument.ToString()); //获取删除行的ID号
- //删除选定的行,并重新指定绑定操作
- this.DeleteRepeater(id);
- }
- else if (e.CommandName == "Update") //更新行内容命令
- {
- //获取更新行的内容和ID号
- string strText = ((TextBox)e.Item.FindControl("txtName")).Text.Trim();
- int intId=int.Parse(((Label)e.Item.FindControl("lblID")).Text);
- //更新Repeater控件的内容
- this.UpdateRepeater(strText,intId);
- }
- //重新绑定控件上的内容
- this.DataBindToRepeater();
- }
- SqlCommand sqlcom = new SqlCommand(); //创建数据库命令对象
- sqlcom.CommandText = "update match set name=@str where id=@id"; //为命令对象指定执行语句
- sqlcom.Connection = sqlCon; //为命令对象指定连接对象
- //创建参数集合,并向sqlcom中添加参数集合
- SqlParameter[] sqlParam = { new SqlParameter("@str", strText), new SqlParameter("@id", intId) };
- sqlcom.Parameters.AddRange(sqlParam);
Repeater控件的的更多相关文章
- ASP.Net中通过Jquery前端对Repeater控件绑定的数据进行操作
说明:由于Repeater控件是动态绑定,通过Id获取数据只能默认获取第一行: 1.对Repeater中div设置样式 2.通过$(".css").each(function(){ ...
- Repeater 控件
Repeater 控件是一个容器控件,可用于从网页的任何可用数据中创建自定义列表.Repeater 控件没有自己内置的呈现功能,这意味着用户必须通过创建模板来提供 Repeater 控件的布局.当网页 ...
- WebForm(四)——Repeater控件(重要、好用)
Repeater控件,可以用来一次显示一组数据项.比如,可以用它们显示一个数据表中的所有行. Repeater控件完全由模板驱动,提供了最大的灵活性,可以任意设置它的输出格式. ...
- Repeater控件用法
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Repeater.aspx. ...
- Repeater控件使用中的一些小问题
网页上用来展示列表的数据,发现还是Repeater比GridView,DetailView之类的要灵活些,所以近期用到了就总结下遇到的一些情况,保留下来以备之后查阅,不用现问度娘了... 自己摸索的, ...
- Repeater控件 ---表格展示数据
简介: Repeater控件是Web 服务器控件中的一个容器控件,它使您可以从页的任何可用数据中创建出自定义列表. Repeater 控件不具备内置的呈现功能,这表示用户必须通过创建模板为 Repea ...
- Repeater控件使用(含删除,分页功能)
Repeater控件使用(含删除,分页功能) 摘自:http://www.cnblogs.com/alanliu/archive/2008/02/25/914779.html 前臺代碼 <%@ ...
- asp.net学习之Repeater控件
asp.net学习之Repeater控件 文章摘自:http://www.cnblogs.com/shipfi/archive/2009/10/19/1585703.html Repeater控件和D ...
- Webform(Repeater控件)
一.Repeater控件 有五大模板 ItemTemplate :有多少条数据,执行多少遍 AlternatingItemTemplate : 对交替数据项进行格式设置 Se ...
- [ASP.NET]asp.net Repeater控件的使用方法
asp.net Repeater控件的使用方法 -- : 4770人阅读 评论() 收藏 举报 asp.netserveraspdatasetdeletexhtml 今天学习了,Repeater控件 ...
随机推荐
- jquery重新渲染的问题
今天动态加载了一个a标记,使他被渲染为linkbutton 在拼该a标记串时,将class属性设置为:class='easyui-linkbutton' ,然而却没有看到linkbutton的效果,原 ...
- SSD-tensorflow-2 evaluation
测试就是用voc2007的test set来测试已经训练好的checkpoint的mAP,github上提供了三个已经训练好的model的checkpoint checkpoint 里面已有的300_ ...
- [国家集训队]拉拉队排练 Manancher_前缀和_快速幂
Code: #include <cstdio> #include <algorithm> #include <cstring> using namespace st ...
- python调用java--JPype
JPype 是一个能够让 python 代码方便地调用 Java 代码的工具,从而克服了 python 在某些领域(如服务器端编程)中的不足.JPype 的使用一个简单的 hello world 程序 ...
- POJ 3630 Phone List(字典树)
题意 题意:t个case(1<=t<=40),给你n个电话号码(电话号码长度<10)(1 ≤ n ≤ 10000),如果有电话号码是另一个电话号码的前缀,则称这个通讯录是不相容的,判 ...
- 紫书 例题 10-29 UVa 1642(最优连续子序列)
这类求最优连续子序列的题一般是枚举右端点,然后根据题目要求更新左端点, 一般是nlogn,右端点枚举是n,左端点是logn 难点在于如何更新左端点 用一些例子试一下可以发现 每次加进一个新元素的时候 ...
- Unity 实现Log实时输出到屏幕或控制台上<二>
本文章由cartzhang编写,转载请注明出处. 所有权利保留. 文章链接:http://blog.csdn.net/cartzhang/article/details/49884507 作者:car ...
- HDFS中的命令行
HDFS中的命令行 本文介绍了HDFS以命令行执行的时候.几个经常使用的命令行的作用和怎样使用~ 1. fs fs是启动命令行动作,该命令用于提供一系列子命令. 使用形式为hadoop fs –cmd ...
- Can’t connect to local MySQL server through socket ‘/tmp/mysql/mysql.sock’解决方法
原因在于/tmp/mysql/mysql.sock不存在,为/usr/local/mysql/mysql.sock建立一个软连接到/tmp/mysql/mysql.sock即可. ln -s /usr ...
- CORS support in Spring Framework--官方
原文地址:https://spring.io/blog/2015/06/08/cors-support-in-spring-framework For security reasons, browse ...