亚洲必赢76net的主页repeater控件的使用,控件之Repeater控件使用

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

<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>

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

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

}

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

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

repeater绑定数据爬山涉水

{

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

}

<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>

html端代碼:

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” %>

}

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();
}
}

{

<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>

</FooterTemplate>

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

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

启用,禁用:

歡迎大家來討論,修正,一定虛心选择。

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();
}
}
}

id=””;

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

protected void reportRepeater_ItemCommand(object source,
RepeaterCommandEventArgs e)

转发自网络-原网站【

<FooterTemplate>

删去数据爬山涉水

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;
}

  關於把從數據庫讀取的數據綁定到前台頁面,作者們可以行使DataGrid、DataGridView以致Repeater來佈局,三者均能够向来綁定DataTable中的字段,不过對於特殊的报表,如需求跨行或跨列顯示的數據,則供给重畫风流洒脱個table,然後再綁定數據。

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

}

C#後端代碼爬山涉水

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

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

}

{

</asp:Panel>

break;

break;

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

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

</ItemTemplate>

if(Page.IsPostBack)

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

1.為什麼使用Repeater控件?

{

<ItemTemplate>

case “CANCEL”:

}

//更新數據庫

case “DELETE”:

 

}

发表评论

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