Repeater动态增添行,repeater控件的选择

ca88会员登录中心

</ItemTemplate>

private void BindStudent()
{
string str =
ConfigurationManager.ConnectionStrings[“stucnn”].ConnectionString;
using (SqlConnection sqlCnn = new SqlConnection
{
using (SqlDataAdapter da = new SqlDataAdapter(“select * from student”,
sqlCnn))
{
DataSet ds = new DataSet();
da.Fill;
this.Repeater1.DataSource = ds;
this.Repeater1.DataBind();
}
}
}

rp_List.DataBind();

<table>

</div>
</form>
</body>
</html>

</td>
<td>
<asp:TextBox ID=”txtSoundSize” runat=”server”
Text='<%#Eval(“soundsize”) %>’></asp:TextBox>
</td>
<td>
<%–<a href=”DuihuaDelete.aspx?id=<%#Eval
%>&page=<%=CurrentPage %>&pianzhangid=<%=pzid %>”
onclick=”return confirm(‘是否删除该数据’)”>删除</a>–%>
<%–<a href=”DuihuaEdit.aspx?id=<%#Eval
%>&pianzhangid=<%=pzid %>” >编辑</a>
<a href=”DuihuaiDetail.aspx?id=<%#Eval%20%>”
title=”详情”>详情</a>–%>
<asp:LinkButton ID=”lbtnDelete” runat=”server” CssClass=”btn
btn-danger” OnClientClick=’return confirm’ CommandName=”del”
CommandArgument='<%#Eval %>’>删除</asp:LinkButton>
<asp:LinkButton ID=”lbtnEdit” runat=”server” CssClass=”btn
btn-default” CommandName=”edit” CommandArgument='<%#Eval
%>’>编辑</asp:LinkButton>
</td>
</ItemTemplate>
<FooterTemplate>
<tr runat=”server” visible=”<%#rp_List.Items.Count==0
%>”>
<td colspan=”9″ >
未找到符合条件的信息
</td>
</tr>
</FooterTemplate>
</asp:Repeater>
</table>

id=””;

<asp:Repeater ID=”Repeater1″ runat=”server”
onitemcommand=”Repeater1_ItemCommand”>
<HeaderTemplate><table>
<tr><td style=”width:100px”>编号</td><td
style=”width:100px”>姓名</td>
<td
style=”width:100px”>图片</td><td> </td><td> </td></tr>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td><%# Eval %></td><td><%# Eval
%></td>
<td><img width=”60px” height=”60px” src='<%# “images/” +
Eval %>’ /></td>
<td><asp:LinkButton ID=”btnDelete” runat=”server” Text=”删除”
CommandName=’Delete’ CommandArgument='<%# Eval
%>’></asp:LinkButton></td>
<td><asp:LinkButton ID=”btnEdit” runat=”server” Text=”编辑”
CommandName=’Edit’ CommandArgument='<%# Eval
%>’></asp:LinkButton></td>
</tr>
</ItemTemplate>
<AlternatingItemTemplate>
<tr style=”
<td><%# Eval %></td><td><%# Eval
%></td>
<td><img width=”60px” height=”60px” src='<%# “images/” +
Eval %>’ /></td>
<td><asp:LinkButton ID=”btnDelete” runat=”server” Text=”删除”
CommandName=’Delete’ CommandArgument='<%# Eval
%>’></asp:LinkButton></td>
<td><asp:LinkButton ID=”btnEdit” runat=”server” Text=”编辑”
CommandName=’Edit’ CommandArgument='<%# Eval
%>’></asp:LinkButton></td>
</tr>
</AlternatingItemTemplate>
<SeparatorTemplate>
<tr><td colspan=”5″><hr /></td></tr>
</SeparatorTemplate>
<FooterTemplate></table></FooterTemplate>
</asp:Repeater>

<table >
<asp:Repeater ID=”rp_List” runat=”server”
onitemcommand=”rp_List_ItemCommand”>
<HeaderTemplate>
<thead>
<tr>
<th>
ID
</th>
<th>
中文内容
</th>
ca88会员登录中心 ,<th>
英文内容
</th>
<th>
是否上传声音<%–(添加时<span >必填</span>)–%>
</th>
<th width=”80px”>
头像
</th>
<th width=”80px”>
对话排序
</th>
<th width=”80px”>
最大时间
</th>
<th width=”80px”>
声音时间
</th>
<th>
操作
</th>
</tr>
</thead>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td>
<%# Container.ItemIndex+1 %>
<asp:HiddenField ID=”hidid” runat=”server” Value='<%#Eval %>’
/>
</td>

<td><%Eval(“nationality”)%></td><tr>

删除数据:

row[“Contenten”] = “”;

</asp:Panel>

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN”
“;

row[“photo”] = “”;

{

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN”
“;

dt.Rows.Add;

protected void BindData()

protected void Page_Load(object sender, EventArgs e)
{
if(!IsPostBack)
BindStudent();
}

newRow[“IsHave”] = item.FindControl(“lblsound”)).Text;

BindData();

repeater绑定数据:

row[“IsHave”] = “未上传”;

}

<html xmlns=”;
<head runat=”server”>
<title></title>
</head>
<body>
<form runat=”server”>
<div>
<asp:Repeater ID=”Repeater1″ runat=”server”
onitemcommand=”Repeater1_ItemCommand”>
<HeaderTemplate><table><tr><th>编号</th><th>姓名</th><th>状态</th><th> </th></tr></HeaderTemplate>
<ItemTemplate>
<tr><td><%# Eval %></td>
<td><%# Eval %></td>
<td><%# Convert.ToBoolean(Eval)?”启用”:”禁用”
%></td>
<td><asp:LinkButton ID=”btnSetStatus” runat=”server”
CommandArgument=’Eval’ Text='<%#
Convert.ToBoolean(Eval)?”禁用”:”启用” %>’ CommandName='<%#
Convert.ToBoolean(Eval)?”false”:”true”
%>’></asp:LinkButton></td></tr>
</ItemTemplate>
<FooterTemplate></table></FooterTemplate>
</asp:Repeater>
</div>
</form>
</body>
</html>

row[“maxsecond”] = “1”;

break;

<html xmlns=”;
<head runat=”server”>
<title></title>
</head>
<body>
<form runat=”server”>
<%–<asp:Repeater ID=”Repeater1″ runat=”server”>
<HeaderTemplate>
<hr />
</HeaderTemplate>
<ItemTemplate><div>
<asp:Label ID=”lblSid” runat=”server” Text='<%# Eval
%>’></asp:Label>
<asp:Label ID=”lblSname” runat=’server’ Text='<%# Eval
%>’></asp:Label>
<asp:Image ID=”imgPhoto” runat=”server” ImageUrl='<%# Eval %>’
/></div>
</ItemTemplate>
<SeparatorTemplate>
<hr />
</SeparatorTemplate>
<AlternatingItemTemplate>
<div style=”
<asp:Label ID=”lblSid” runat=”server” Text='<%# Eval
%>’></asp:Label>
<asp:Label ID=”lblSname” runat=’server’ Text='<%# Eval
%>’></asp:Label>
<asp:Image ID=”imgPhoto” runat=”server” ImageUrl='<%# Eval %>’
/></div>
</AlternatingItemTemplate>
<FooterTemplate><hr /></FooterTemplate>
</asp:Repeater>–%>
<div>

rp_List.DataSource = dt;

{

转载自网络-原网址【

DataRow row = dt.NewRow();

<th>籍貫</th>

启用,禁用:

}

if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==
ListItemType.AlternatingItem)//
{

protected void Repeater1_ItemCommand(object source,
RepeaterCommandEventArgs e)
{
if (e.CommandName == “Delete”)
{
string str =
ConfigurationManager.ConnectionStrings[“stucnn”].ConnectionString;
using (SqlConnection sqlCnn = new SqlConnection
{
using (SqlCommand sqlCmm = sqlCnn.CreateCommand
{
sqlCnn.Open();
sqlCmm.CommandText = “delete from student where sEdit”)
{
Server.Transfer(“Edit.aspx?sC#” AutoEventWireup=”true”
CodeFile=”Default.aspx.cs” Inherits=”_Default” %>

row[“orderby”] = “0”;

}

protected void Repeater1_ItemCommand(object source,
RepeaterCommandEventArgs e)
{
//string status = e.CommandName;
if ((e.CommandName == “true”)||(e.CommandName == “false”))
{
string str =
ConfigurationManager.ConnectionStrings[“stucnn”].ConnectionString;
using (SqlConnection sqlCnn = new SqlConnection
{
using (SqlCommand sqlCmm = sqlCnn.CreateCommand
{
sqlCnn.Open();
sqlCmm.CommandText = “update student setstatus=@statuswhere
s@status”,e.CommandName);
sqlCmm.ExecuteNonQuery();
}
}
this.BindStudent();
}
}

row[“soundsize”] = “1”;

ImageUrl=”../Images/update.gif” runat=”server” Visible=”false” />

<%@ Page Language=”C#” AutoEventWireup=”true”
CodeFile=”Default2.aspx.cs” Debug=”true” Inherits=”Default2″ %>

row[“Contentzh”] = “”;

reportRepeater.DataBind();

DataTable dt = DefineDataTableSchema(hfRptColumns.Value);

DAL.DAL dal = new DAL.DAL();

}

{

protected void btnAddNewRow_Click(object sender, EventArgs e)
{

//更新數據庫

/// <summary>
/// 根据repeater相对应的列名,定义数据源datatable的schema
/// </summary>
/// <param name=”columns”>列名</param>
/// <returns></returns>
public DataTable DefineDataTableSchema(string columns)
{
DataTable dt = new DataTable();
string[] columnsAry = columns.Split;
foreach (string str in columnsAry)
{
dt.Columns.Add;
}
return dt;
}

}

<td>
<asp:TextBox ID=”txtCountentzh” runat=”server”
Text='<%#Eval(“Contentzh”) %>’ ></asp:TextBox>
</td>
<td>
<asp:TextBox ID=”txtCountenten” runat=”server”
Text='<%#Eval(“Contenten”) %>’ ></asp:TextBox>
</td>
<td>
<%–<asp:FileUpload ID=”FileUpload” runat=”server”
CssClass=”form-control” />–%>
<asp:Label ID=”lblsound” runat=”server” Text='<%#Eval
%>’></asp:Label>
</td>
<td>
<asp:TextBox ID=”txtPhoto” runat=”server” Text='<%#Eval
%>’></asp:TextBox>
</td>
<td>
<asp:TextBox ID=”txtOrder” runat=”server”
Text='<%#Eval(“orderby”) %>’></asp:TextBox>
</td>
<td>
<asp:TextBox ID=”txtMaxsecond” runat=”server”
Text='<%#Eval(“maxsecond”) %>’></asp:TextBox>

3.Repeater控件一些基礎設定

foreach (RepeaterItem item in rp_List.Items)

<td><%#Eval(“birthplace”)%></td>

newRow[“soundsize”] = item.FindControl(“txtSoundSize”)).Text;

  關於把從數據庫讀取的數據綁定到前台頁面,我們可以使用DataGrid、DataGridView以及Repeater來佈局,三者均可以直接綁定DataTable中的字段,但是對於特殊的表格,如需要跨行或跨列顯示的數據,則需要重畫一個table,然後再綁定數據。

newRow[“Contenten”] = item.FindControl(“txtCountenten”)).Text;

<tr><th></th>

//添加一行

BindData();

newRow[“id”] = ((HiddenField)item.FindControl.Value;

case “CANCEL”:

//首先,恢复数据源

System.Data.DataRowView record =
(System.Data.DataRowView)e.Item.DataItem;
string userID= record[“userID”].ToString();
if
(userID.Equals(id))//當點擊不同的按鈕時對Pannel控件進行隱藏和顯示,達到在table內編輯行的效果
{
((Panel)e.Item.FindControl(“plItem”)).Visible = false;
((Panel)e.Item.FindControl(“plEdit”)).Visible = true;
}
else
{
((Panel)e.Item.FindControl(“plItem”)).Visible = true;
((Panel)e.Item.FindControl(“plEdit”)).Visible = false;
}

DataRow newRow = dt.NewRow();

<td><%#Eval(“username”)%></td>

newRow[“orderby”] = item.FindControl(“txtOrder”)).Text;

{

newRow[“photo”] = item.FindControl(“txtPhoto”)).Text;

<asp:ImageButton ID=”imgInvDelete” CommandName=”DELETE”
ToolTip=”刪除” CommandArgument='<%#Eval(“userID”)%>’
ImageUrl=”../Images/delete.gif” runat=”server” Visible=”false”
/></td>

后台代码:

if(Page.IsPostBack)

dt.Rows.Add;

{

newRow[“maxsecond”] = item.FindControl(“txtMaxsecond”)).Text;

<tr><td><asp:ImageButton ID=”imgInvEdit”
CommandName=”EDIT” ToolTip=”編輯”
CommandArgument='<%#Eval(“userID”)%>’

newRow[“Contentzh”] = item.FindControl(“txtCountentzh”)).Text;

 

{

歡迎大家來討論,修改,一定虛心接受。

protected void reportRepeater_ItemDataBound(object sender,
RepeaterItemEventArgs e)//Item綁定時可以在此做一些操作

  我們可以自由的定義Table的表頭、表身和表尾。

</table>

C#後端代碼:

<td><%#Eval(“birthplace”)%></td>

<tr><td><asp:ImageButton ID=”imgInvUpdate”
CommandName=”UPDATE” ToolTip=”更新”
CommandArgument='<%#Eval(“userID”)%>’

<asp:Panel ID=”plItem” runat=”server”>

<asp:ImageButton ID=”imgInvCancel” CommandName=”CANCEL”
ToolTip=”取消” CommandArgument='<%#Eval(“userID”)%>’
ImageUrl=”../Images/cancel.gif” runat=”server” Visible=”false”
/></td>

<td><%#Eval(“userID”)%></td>

<th>用戶ID</th>

</asp:Panel>

<ItemTemplate>

switch (e.CommandName.Trim().ToUpper())
{
case “EDIT”:
{
id = e.CommandArgument.ToString();
break;
}
case “UPDATE”:

</FooterTemplate>

}

case “DELETE”:

//從數據庫刪除

<td><%Eval(“nationality”)%></td><tr>

{

<td><%#Eval(“userID”)%></td>

ImageUrl=”../Images/edit1.gif” runat=”server” Visible=”false” />

{

<FooterTemplate>

1.為什麼使用Repeater控件?

  例:以下例子展示了如何對Repeater控件進行綁定,并實現在table中實現編輯和更新數據行的操作

string sql = “select * from user”;

2.Repeater控件之好處

}

<th>用戶名</th>

<asp:Panel ID=”plItem” runat=”server”>

<th>民族</th></tr>

//數據綁定

protected void reportRepeater_ItemCommand(object source,
RepeaterCommandEventArgs e)

<td><%#Eval(“username”)%></td>

reportRepeater.DataSource = dt;

</HeaderTemplate>

}

}

break;

<asp:Repeater runat=”server” ID=”reportRepeater”
OnItemCommand=”reportRepeater_ItemCommand”
OnItemDataBound=”reportRepeater_ItemDataBound”>
<HeaderTemplate>

}

break;

protected void Page_Load(object sender, EventArgs e)
{

 

DataTable dt = dal.ExecuteDataSet(Properties.Settings.Default.DBWF,
sql).Tables[0];

html端代碼:

}

发表评论

电子邮件地址不会被公开。 必填项已用*标注

网站地图xml地图