网页上用来展示列表的数据,发现还是Repeater比GridView,DetailView之类的要灵活些,所以近期用到了就总结下遇到的一些情况,保留下来以备之后查阅,不用现问度娘了...

自己摸索的,很可能有不正确的地方,望前辈指正。

1. Repeater控件绑定可以是数组,比如某个类的实例数组

 //前台代码
<asp:Repeater ID="repeater" runat="server"
onitemcommand="repeater_ItemCommand" >
<HeaderTemplate>
<table><thead><tr>
<td>ID</td><td>Name</td><td>修改</td><td>删除</td>
</tr></thead>
</HeaderTemplate>
<ItemTemplate>
<asp:Panel ID="pnl_display" runat="server" Visible="true">
<tr>
<td><%#Eval("PKID") %></td>
<td><a href='NewsSmallClassManage.aspx?bgid=<%#Eval("PKID") %>'><%#Eval("FirstLevelName")%></a></td>
<td><asp:LinkButton ID="lbtnModify" CommandName="edit" runat="server" Text="修改" ></asp:LinkButton></td>
<td><asp:LinkButton ID="lbtnDelete" CommandName="delete" CommandArgument='<%#Eval("PKID") %>' runat="server" Text="删除" OnClientClick='return confirm("确定要删除该大类吗?");'></asp:LinkButton></td>
</tr>
</asp:Panel>
<asp:Panel ID="pnl_edit" runat="server" Visible="false">
<tr>
<td><%#Eval("PKID") %></td>
<td><asp:TextBox ID="txtBigClassName" runat="server" Text='<%#Eval("FirstLevelName") %>'></asp:TextBox></td>
<td><asp:LinkButton ID="lbtUpdate" CommandName="update" CommandArgument='<%#Eval("FirstLevelName") %>' runat="server" Text="更新"></asp:LinkButton></td>
<td><asp:LinkButton ID="lbtCancel" CommandName="cancel" runat="server" Text="取消"></asp:LinkButton></td>
</tr>
</asp:Panel>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
 //后台代码
NewsClass[] array = IS.Business.NewsClassBLL.GetFirstLevelClass();
repeater.DataSource = array;
repeater.DataBind();

2. 使用CommondArgument向后台传递参数,在ItemCommand事件中处理控件内按钮的命令相应

        protected void repeater_ItemCommand(object source, RepeaterCommandEventArgs e)
{
switch (e.CommandName)
{
case "edit":
((Panel)e.Item.FindControl("pnl_display")).Visible = false;
((Panel)e.Item.FindControl("pnl_edit")).Visible = true;
break; case "cancel":
((Panel)e.Item.FindControl("pnl_display")).Visible = true;
((Panel)e.Item.FindControl("pnl_edit")).Visible = false;
break; case "delete":
try
{
IS.Business.NewsClassBLL.Delete(int.Parse(e.CommandArgument.ToString()));
this.bindData();
}
catch (Exception ex)
{
Functions.AlertMsg(ex.Message, Page);
}
break; case "update":
string oldname = e.CommandArgument.ToString();
string newname = ((TextBox)e.Item.FindControl("txtBigClassName")).Text;
try
{
IS.Business.NewsClassBLL.RenameFirstLevelClassName(oldname, newname);
this.bindData();
}
catch (Exception ex)
{
Functions.AlertMsg(ex.Message, Page);
}
break; default:
break;
}
}

3. 两个Panel用来实现类似就地编辑的功能。好像用PlaceHolder更好一点,不会生成额外的html标签。

4. 被绑定的类里面还有一个其他类的实例作为其属性成员,绑定其属性成员的某个属性时使用:

<%#DataBinder.Eval(((IS.Model.Exhibition)Container.DataItem).Area,"Name") %>

5. 加个行号:

<%#Container.ItemIndex+ %>

6. 格式化输入某些变量,以时间为例:

<%#DataBinder.Eval(Container.DataItem,"StartTime","{0:yyyy-MM-dd}") %>

Repeater控件使用中的一些小问题的更多相关文章

  1. ASP.NET Repeater控件实现简单分页

    早上,有看MSDN,看到了 PagedDataSource 类 http://msdn.microsoft.com/zh-cn/library/system.web.ui.webcontrols.pa ...

  2. Repeater控件的分隔线

    在Repeater控件中,很容易实现在行与行之间使用分隔线.因为此控件有内置的SeparatorTemplate模版.举个例子吧: 运行时,可以看到效果: 说句实在的话,Insus.NET做一条水平线 ...

  3. ASP.Net中通过Jquery前端对Repeater控件绑定的数据进行操作

    说明:由于Repeater控件是动态绑定,通过Id获取数据只能默认获取第一行: 1.对Repeater中div设置样式 2.通过$(".css").each(function(){ ...

  4. Repeater 控件

    Repeater 控件是一个容器控件,可用于从网页的任何可用数据中创建自定义列表.Repeater 控件没有自己内置的呈现功能,这意味着用户必须通过创建模板来提供 Repeater 控件的布局.当网页 ...

  5. WebForm(四)——Repeater控件(重要、好用)

    Repeater控件,可以用来一次显示一组数据项.比如,可以用它们显示一个数据表中的所有行.             Repeater控件完全由模板驱动,提供了最大的灵活性,可以任意设置它的输出格式. ...

  6. Repeater控件用法

    <%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Repeater.aspx. ...

  7. Repeater控件 ---表格展示数据

    简介: Repeater控件是Web 服务器控件中的一个容器控件,它使您可以从页的任何可用数据中创建出自定义列表. Repeater 控件不具备内置的呈现功能,这表示用户必须通过创建模板为 Repea ...

  8. Repeater控件使用(含删除,分页功能)

    Repeater控件使用(含删除,分页功能) 摘自:http://www.cnblogs.com/alanliu/archive/2008/02/25/914779.html 前臺代碼 <%@ ...

  9. asp.net学习之Repeater控件

    asp.net学习之Repeater控件 文章摘自:http://www.cnblogs.com/shipfi/archive/2009/10/19/1585703.html Repeater控件和D ...

随机推荐

  1. Word Break

    Given a string s and a dictionary of words dict, determine if s can be segmented into a space-separa ...

  2. 默认.htpl改为.htpl

    创建一个.html 或.htpl 在打开的html页面空白处右击--属性

  3. eclipse界面混乱

    在eclipse最右边点击Java----reset

  4. 深入探讨在集群环境中使用 EhCache 缓存系统

    EhCache 缓存系统简介 EhCache 是一个纯 Java 的进程内缓存框架,具有快速.精干等特点,是 Hibernate 中默认的 CacheProvider. 下图是 EhCache 在应用 ...

  5. jQuery HTML

    alert("Text: " + $("#test").text());获取text alert("HTML: " + $("#t ...

  6. getEnhancedMicrophone 方法

    [转]http://www.cnblogs.com/iBlogger/archive/2011/11/16/2251847.html Flex 4.6 SDK 提供了 getEnhancedMicro ...

  7. Angularjs 服务注册

    $injector: (When you request a service, the $injector is responsible for finding the correct service ...

  8. SSM框架的整合思路&功能实现

    这是我第一篇博客,关于SSM框架的整合思路以及简单功能实现. 首先,最近刚刚学习Spring+SpringMVC+Mybatis,在开发时遇到形形色色的问题,周遭人也为我提供了一些思路,我会一点点整理 ...

  9. CE 进程间通信

    WINCE下进程间通信常用的方式有:剪贴板(Clipboard),网络套接字(Socket),WM_COPYDATA消息,共享内存,管道(消息队列),注册表等 剪贴板 //////////////// ...

  10. first

    不知道学啥,怎么办,写博客.找不到工作,怎么办,写博客.好吧,第一天博客完成.-渣渣米