ASP.NET — repeater控件的接收

BindData();

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

复制代码

DataTable dt = DefineDataTableSchema(hfRptColumns.Value);

C#後端代碼:

转载自网络-原网址【

        /// <summary>
        /// repeater数据默认加载
        /// </summary>
        /// <param name=”dt”></param>
        private void LoadData(DataTable dt)
        {
            //默认显示1行
            for (int i = 0; i < 1; i++)
            {
                DataRow row = dt.NewRow();
                dt.Rows.Add(row);
            }

}

case “CANCEL”:

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

  

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

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

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

前台:

row[“maxsecond”] = “1”;

string sql = “select * from user”;

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

<asp:Repeater ID=”Repeater1″ runat=”server”>
                <HeaderTemplate><table cellpadding=”0″
cellspacing=”0″ border=”1″ align=”center” class=”auto-style1″>
                    <tr align=”left”>
                        <th>编号</th>
                        <th>姓名</th>
                        <th>年龄</th>
                        <th>班级</th>
                        <th>零花</th>
                    </tr>
                  </HeaderTemplate>
                <ItemTemplate>
                    <tr >
                        <td><%#Eval(“id”)%></td>
                        <td><%#Eval(“name”)%></td>
                        <td><%#Eval(“age”)%></td>
                       
<td><%#Eval(“classid”)%></td>
                       
<td><%#Eval(“salary”)%></td>
                    </tr>
                </ItemTemplate>
               
<FooterTemplate></table></FooterTemplate>
            </asp:Repeater>

rp_List.DataBind();

protected void reportRepeater_ItemCommand(object source,
RepeaterCommandEventArgs e)

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

 代码如下

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

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

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

后台:

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

html端代碼:

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

                //首先,恢复数据源
                DataTable dt =
DefineDataTableSchema(hfRptColumns.Value);
                foreach (RepeaterItem item in rptRequest.Items)
                {
                    DataRow newRow = dt.NewRow();
                    newRow[“Guid”] =
((System.Web.UI.WebControls.Label)item.FindControl(“lblGuid”)).Text;
                    newRow[“EquRequestItemId”] =
((System.Web.UI.WebControls.Label)item.FindControl(“lblEquRequestItemId”)).Text;
                    newRow[“EquipmentType”] =
((DropDownList)item.FindControl(“ddlEquipmentType”)).SelectedValue;
                    newRow[“Station”] =
((DropDownList)item.FindControl(“ddlStation”)).SelectedValue;
                    newRow[“EquipmentNum”] =
((TextBox)item.FindControl(“txtReqEquipmentNum”)).Text;
                    newRow[“EquipmentIds”] =
((TextBox)item.FindControl(“txtEquipmentIds”)).Text;
                    dt.Rows.Add(newRow);

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

{

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

                //首先,恢复数据源
                DataTable dt =
DefineDataTableSchema(hfRptColumns.Value);
                foreach (RepeaterItem item in rptRequest.Items)
                {
                    if (lblGuid.Text !=
((System.Web.UI.WebControls.Label)item.FindControl(“lblGuid”)).Text)
                    {
                        DataRow newRow = dt.NewRow();
                        newRow[“Guid”] =
((System.Web.UI.WebControls.Label)item.FindControl(“lblGuid”)).Text;
                        newRow[“EquRequestItemId”] =
((System.Web.UI.WebControls.Label)item.FindControl(“lblEquRequestItemId”)).Text;
                        newRow[“EquipmentType”] =
((DropDownList)item.FindControl(“ddlEquipmentType”)).SelectedValue;
                        newRow[“Station”] =
((DropDownList)item.FindControl(“ddlStation”)).SelectedValue;
                        newRow[“EquipmentNum”] =
((TextBox)item.FindControl(“txtReqEquipmentNum”)).Text;
                        newRow[“EquipmentIds”] =
((TextBox)item.FindControl(“txtEquipmentIds”)).Text;
                        dt.Rows.Add(newRow);
                    }
                }

row[“Contentzh”] = “”;

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

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

/// <summary>
        /// 绑定repeater的数据源
        /// </summary>
        private void RepeaterBindData()
        {
            DataTable dt = DefineDataTableSchema(hfRptColumns.Value);
            if (Request[“BusinessNo”] == null)
            {
                LoadData(dt);
            }
            else
            {
                LoadData(Request[“BusinessNo”].ToString(), dt);
            }

foreach (RepeaterItem item in rp_List.Items)

}

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

            //for (int i = 0; i <
dt_EquipmentRequestItem.Rows.Count; i++)
            foreach (DataRow
dr in dt_EquipmentRequestItem.Rows)
            {
                DataRow row = dt.NewRow();
                row[“Guid”] = Guid.NewGuid();
                row[“EquRequestItemId”] =
dr[“EquRequestItemId”].ToString();
                row[“EquipmentType”] = dr[“TypeId”].ToString();
                row[“Station”] = dr[“StationId”].ToString();
                row[“EquipmentNum”] =
dr[“EquipmentNum”].ToString();
                row[“EquipmentIds”] =
dr[“EquipmentIds”].ToString();
                dt.Rows.Add(row);
            }
        }

row[“orderby”] = “0”;

}

启用,禁用:

repeater控件动态添加、删除一行

row[“Contenten”] = “”;

 

repeater绑定数据:

 代码如下

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

}

删除数据:

        protected void rptRequest_ItemDataBound(object sender,
RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType
== ListItemType.AlternatingItem)
            {
                DropDownList ddlEquipmentType_temp =
e.Item.FindControl(“ddlEquipmentType”) as DropDownList;

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

break;

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

                            if (dt.Rows.Count != 0 &&
dt.Rows[0][“LayerName”].ToString() == “资产管理员”)
                            {
                                string ReqNum =
(e.Item.FindControl(“txtReqEquipmentNum”) as TextBox).Text.Trim();
                                txtEquIds.Attributes.Add(“onclick”,
“OpenWindow(‘” + txtEquIds.ClientID + “‘,'” +
ddlEquipmentType_temp.SelectedValue + “‘,'” + ReqNum + “‘)”);
                            }
                        }
                    }
 
                }

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

//更新數據庫

  

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

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

AspNetpager的使用方法:

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

protected void Page_Load(object sender, EventArgs e)
{

            rptRequest.DataSource = dt;
            rptRequest.DataBind();
        }

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

<ItemTemplate>

  • asp.net
    repeater控制使用示例详解
  • asp.net中子级Repeater获取父级Repeater绑定项的值
    Eval
  • Repeater和GridView支持DataPager分页做法
  • repeater或DataList控件简单应用
  • asp.net 中Repeater 的方法
  • asp.net
    Repeater绑定数据源的方法
  • Repeater获取控件对象与数据绑定
  • asp.net Repeater控件详解
  • asp.net
    Repeater排序用的控件应用与详解
  • Repeater
    Button控件并响应单击操作的方法

row[“soundsize”] = “1”;

{

复制代码

protected void btnAddNewRow_Click(object sender, EventArgs e)
{

reportRepeater.DataSource = dt;

        protected void rptRequest_ItemCommand(object source,
RepeaterCommandEventArgs e)
        {
            if (e.CommandName == “add”)
            {
                System.Web.UI.WebControls.Label lblGuid =
(System.Web.UI.WebControls.Label)e.Item.FindControl(“lblGuid”);

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

发表评论

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