在ASP 中的Repeater控件进行数据绑定后,在页面中可以显示数据行,但数据行是不可编辑的,怎样去获取数据行中的一个字段。
解决方案 »
- repeater列头排序问题
- 水晶报表显示小尺寸图片?
- c#.net通过程序如何导入mysql脚本
- 客户端从文本文件里读内容,提示登录失败: 未知的用户名或错误密码。
- 怎样解决在ASP.NET中出现相同问题编号的问题
- 一张页面上有一个按钮并且内嵌一个iframe 怎么用按纽取出iframe里面的<INPUT name="text2" type="text" id="unchecked">值
- 问一个很小的问题!
- C# GDI+底层开发的文本编辑器源码
- 新手求教~~~有关存储过程的问题
- 关于日期类型生成XML文件
- GridView倒出到EXCEL的问题
- page_load中事件只用一次的问题!用户自定义皮肤入库问题!!!
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Repeater1.DataSource = BuildDataSource();
Repeater1.DataBind();
}
} /// <summary>
/// 用来做例子中的数据源
/// </summary>
/// <returns></returns>
private DataTable BuildDataSource()
{
DataTable dt = new DataTable();
dt.Columns.Add("Number"); DataRow dr = dt.NewRow();
dr["Number"] = "1000";
dt.Rows.Add(dr); dr = dt.NewRow();
dr["Number"] = "1001";
dt.Rows.Add(dr); return dt;
}
protected void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e)
{
if (e.CommandName.Equals("SELECT"))
{
//你点击的Button
Button bt = e.Item.FindControl("Button1") as Button;
//和Button在同一行的TextBox
TextBox tb = e.Item.FindControl("TextBox1") as TextBox;
Response.Write("你选中行的TextBox的值:" + tb.Text);
}
}
}<%@ Page Language="C#" AutoEventWireup="true" CodeFile="RepeaterSamples.aspx.cs" Inherits="RepeaterSamples" %><!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>Repeater samples</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Repeater ID="Repeater1" runat="server" OnItemCommand="Repeater1_ItemCommand">
<ItemTemplate>
<table><tr><td>
<asp:Button ID="Button1" runat="server" Text="Button1" CommandName="SELECT"/>
<td> <asp:TextBox runat="server" ID="TextBox1" Text='<%# Eval("Number") %>' /></td>
</td></tr></table>
</ItemTemplate>
</asp:Repeater>
</div>
</form>
</body>
</html>
Repeater允许对数据记录作最大限度的HTML定制但它不支持内建的编辑、排序和分页功能
点击选择时把那一行的数据取出来编辑:
具体代码如下:
------------------------------------------------------ if (e.CommandName == "Edit")
{
int id = int.Parse(((HiddenField)(e.Item.FindControl("hfPowerInfo"))).Value);
KingCms.Web.Code.Model.Module_Role moduleRole=new KingCms.Web.Code.Model.Module_Role ();
moduleRole =iModuleRole.GetModel (id );
txtPath.Text = moduleRole.Path;
txtRe.Text = moduleRole.Re;
txtTitle.Text = moduleRole.Title;
ddlModuleID.SelectedValue = moduleRole.ModuleID.ToString();
hidId.Value = moduleRole.ID.ToString();
}然后单独更新。