澳门新萄京:net中Repeater控件用法笔记,控件之
分类:www.澳门新萄京赌场

歡迎大家來討論,修正,一定虛心接纳。

转载自网络-原网站【

大家可能都对datagrid相比熟悉,不过假如在数据量大的时候,大家就得思忖选取repeater作为我们的数目绑定控件了。Repeater控件与DataGrid (以至DataList卡塔尔控件的重视差异是在意怎么样管理HTML。ASP.NET塑造HTML代码以突显DataGrid控件,但Repeater允许开辟职员决定哪些显示数据。所以,你能够选拔将数据突显在二个HTML表格中要么贰个相继列表中。这主要在于你的抉择,但你必须要将科学的HTML插入到 ASP.NET页面中。
   模板与DataList同样,Repeater控件只扶助模板。以下的模版可供采取:
  AlternatingItemTemplate: 钦定怎么着体现每豆蔻梢头任何选项。
  ItemTemplate: 钦定怎么着显示选项。(AlternatingItemTemplate能够覆盖这一模板。卡塔尔(قطر‎
   HeaderTemplate: 创建怎样显示标题。
  FooterTemplate: 建构如何突显页脚。
  SeparatorTemplate: 钦定怎样体现分裂选择之间的分隔符。
  你能够采纳这么些模板来展现你希望的数量。唯后生可畏全体强迫性的模版是ItemTemplate,全数其余的模板都以颇有接纳性的。
  对于拍卖四个数据源,Repeater控件具有与DataGrid与DataList相仿的特性:
 
  DataMember:获得恐怕设置与 Repeater 控件绑定的照应DataSource属性的表格。
 
  DataSource:获得大概设置为 Repeater 展现提供数据的数据源。
 
  除此而外,还会有多少个Items属性,你能够透过那意气风发属性编制程序访谈Repeater数据中单风姿罗曼蒂克选项。它回到多少个RepeaterItemCollection对象,为豆蔻年华组RepeaterItem对象的会见,代表 Repeater 数据的每意气风发行。
 
  ASP.NET Web数据控件还应该有任何叁个共性:它们都应用DataBind方法来变化顾客分界面。调用那风华正茂主意能够回来并展现数据(就算DataSource和 DataMember属性设置科学卡塔尔(قطر‎。在查看DataBind方法在此以前,大家先看看哪些在八个Web页面中接收叁个Repeater控件。
      使用Repeater控件
  使用Repeater控件的率先步骤是调整我们将在采用的数据源和字段。举例,大家就要利用SQL Server Northwind数据库中的Employees列表。Web页面将显得职工的完整名字,地址,以至电话号码。HTML将应用DIV标志,用 Repeater 模板来分隔内容。上面是 Web 页面包车型大巴 HTML 内容:

<table >
<asp:Repeater ID="rp_List" runat="server" onitemcommand="rp_List_ItemCommand">
<HeaderTemplate>
<thead>
<tr>
<th>
ID
</th>
<th>
中文内容
</th>
<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>

asp.net学习之Repeater控件

 

    Repeater控件和DataList控件,能够用来一回显示风度翩翩组数据项。比方,能够用它们显示一个数额表中的装有行。 
    Repeater控件完全由模板驱动,提供了最大的圆滑,能够自由设置它的出口格式。DataList控件也由模板驱动,和Repeater区别的是,DataList暗许输出是HTML表格,DataList将数据源中的记录输出为HTML表格四个个的单元格。

 

repeater绑定数据:

前台代码

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

1. Repeater控件突显数据

    要接受Repeater控件显示数据,必需成立ItemTemplate。如下所示: 
例1:使用ItemTemplate呈现数据 

澳门新萄京 1
<asp:Repeater ID="Repeater1" runat="server" DataSourceID="SqlDataSource1">
    <ItemTemplate>
        <div class="movies">
            <h1><%#Eval("Title") %></h1>
        </div>
        <b>Directed by:</b><%#Eval("Director") %>
        <br />
        <b>Description:</b><%#Eval("Description") %>
    </ItemTemplate>
</asp:Repeater> 

    以上代码,通过浏览器能够见见,.net不会变动里面包车型大巴协会,模板里面怎么排列,数据呈现也什么展现。它的HTML如下所示:、 

澳门新萄京 2
<div class="movies">
     <h1>Smith行动</h1>
</div>
<b>Directed by:</b>Doug Liman
<br />
<b>Description:</b>约翰(布拉德?皮特 Brad Pitt 饰)和
<div class="movies">
     <h1>暴力街区</h1>
</div>
<b>Directed by:</b>Luc Besson
<br />
<b>Description:</b>藏龙卧虎而又车水马龙的13区… 

    所以,Repeater的灵活性就在这里个方面,完全能够自由发挥,想怎么显得就怎么显得。举个例子,都得以把它身处Javascript代码中 

澳门新萄京 3
<script type=”text/javascript”>
    <asp:Repeater id=”rptPhotos” Runat=”server”>
         <ItemTemplate>
              <%# Eval(“Name”, "photos.push(‘Photos/{0}’)") %>
         </ItemTemplate>
    </asp:Repeater>
</script> 

   以上,photos是一个Javscript数组对象。Repeater生成的数目,最终就好像以下那样: 

澳门新萄京 4
<script type="text/javascript">
        photos.push('Photos/1.jpg');
        photos.push('Photos/2.jpg');
        photos.push('Photos/3.jpg');
        photos.push('Photos/4.jpg');
        …
</script> 

 

1.為什麼使用Repeater控件?

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

 代码如下

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

2. Repeater中利用模板

    Repeater扶植以下5种模板 
      ● ItemTemplate : 对每一个多少项举行格式设置 【Formats each item from the data source.】 
      ● AlternatingItemTemplate : 对更换数据项举办格式设置 
      ● SeparatorTemplate : 对分隔符举办格式设置 
      ● HeaderTemplate : 对页眉实行格式设置 
      ● FooterTemplate : 对页脚实行格式设置 
   以上,乌克兰语中应用了Formats item from datasource那样的话,就证实Repeater控件首如若用来对数码实行Format的,调节数据如何排列,如何彰显。 
   Repeater必需利用的是Itemtemplate,其余的品种模板按需加上。 
例2:以下通过CSS调整,展现了二个相比不易的列表项: 

澳门新萄京 5
<style type="text/css">
    html {
        background-color:Silver
    }
    .content {
        width:600px;
        border:soild 1px black;
        background-color:White;
    }
    .movies {
        border-collapse:collapse;
    }
    .movies th,.movies td {
        padding:10px;
        border-bottom:1px solid black;
    }
    .alternating {
        background-color:#eeeeee;
        }
</style>

<div class="content">
<asp:Repeater ID="Repeater1" runat="server" DataSourceID="SqlDataSource1">
    <HeaderTemplate> <!-- 展现底部 -->
        <table class="movies"> <!-- table底部声称-->
         <tr>
            <th>Movie Title</th>
            <th>Movie Director</th>
            <th>Box Office Totals</th>
         </tr>
    </HeaderTemplate>
    <ItemTemplate>  <!-- 数据行 -->
        <tr>
            <td><%#Eval("Title") %></td>
            <td><%#Eval("Director") %></td>
            <td><%#Eval("BoxOfficeTotals","{0:c}") %></td> <!-- 格式化为货币方式 -->
        </tr>
    </ItemTemplate>
    <AlternatingItemTemplate> <!-- 交错行 -->
        <tr class="alternating">
            <td><%#Eval("Title") %></td>
            <td><%#Eval("Director") %></td>
            <td><%#Eval("BoxOfficeTotals","{0:c}") %></td>
        </tr>
    </AlternatingItemTemplate>
    <FooterTemplate> <!-- 脚注行 -->
        </table>    <!-- table尾 -->
    </FooterTemplate>
</asp:Repeater>
</div> 

    以上,展现的体制如下所示: 

澳门新萄京 6 

  關於把從數據庫讀取的數據綁定到前台頁面,笔者們能够利用DataGrid、DataGridView以致Repeater來佈局,三者均能够平素綁定DataTable中的字段,可是對於特殊的表格,如供给跨行或跨列顯示的數據,則须要重畫意气风发個table,然後再綁定數據。

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

复制代码

后台代码:

3. Repeater控件的事件管理

    Repeater控件有以下事件: 
      ● DataBinding : Repeater控件绑定到数码源时触发 
      ● ItemCommand : Repeater控件中的子控件触发事件时触发 
      ● ItemCreated : 成立Repeater种种品种时触发  
      ● ItemDataBound : Repeater控件的各样项目绑定数据时触发 
例3:使用Repeater控件的风云帮忙编辑、更新、删除 
=== 后台代码 === 

澳门新萄京 7
<script runat=”server”>
    // The name of the primary key column
    string DataKeyName = "Id";

    /// 把种种列的ID存款和储蓄在ViewState["Keys"]对象中,ViewState["Keys"]是一个HashTable对象。
    Hashtable Keys
    {
        get
        {
            if (ViewState["Keys"] == null)
                ViewState["Keys"] = new Hashtable();
            return (Hashtable)ViewState["Keys"];
        }
    }

    /// Repeater控件绑定到数量源时触发
    /// 每一遍换代,删除,扩张后,都会接触这几个事件,Keys中的值都会被免去。
    /// 在ItemDataBound事件发生时,被新的值填充
    protected void rptMovies_DataBinding(object sender, EventArgs e)
    {
        Keys.Clear();
    }

    /// 各类品种绑定数据时接触
    protected void rptMovies_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        // 借使是数据列,把ID列收取来,参加到ViewState["Keys"]中
        // DataBinder.Eval是在运维时计算数据绑定表明式。那样的用法要记住.
        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==ListItemType.AlternatingItem)
        {
            Keys.Add(e.Item.ItemIndex, DataBinder.Eval(e.Item.DataItem, "Id"));
        }
    }

    /// 当点击Update,Insert,Delete按键时接触
    protected void rptMovies_ItemCommand(object source, RepeaterCommandEventArgs e)
    {
        switch (e.CommandName)
        {
            case "Update":
                UpdateMovie(e);
                break;
            case "Insert":
                InsertMovie(e);
                break;
            case "Delete":
                DeleteMovie(e);
                break;
        }
    }
    /// Update a movie record
    protected void UpdateMovie(RepeaterCommandEventArgs e)
    {
        // 从八个数码项中得到相应的控件
        TextBox txtTitle = (TextBox)e.Item.FindControl("txtTitle");
        TextBox txtDirector = (TextBox)e.Item.FindControl("txtDirector");
        CheckBox chkInTheaters = (CheckBox)e.Item.FindControl("chkInTheaters");
        // 填充sqlDataSource的UpdateParameters值
        srcMovies.UpdateParameters["Id"].DefaultValue =
        Keys[e.Item.ItemIndex].ToString();
        srcMovies.UpdateParameters["Title"].DefaultValue = txtTitle.Text;
        srcMovies.UpdateParameters["Director"].DefaultValue = txtDirector.Text;
        srcMovies.UpdateParameters["InTheaters"].DefaultValue =
        chkInTheaters.Checked.ToString();
        // 进行Update
        srcMovies.Update();
    }

    /// Insert a movie record
    protected void InsertMovie(RepeaterCommandEventArgs e)
    {
        // 从叁个数据项中拿到对应的控件
        TextBox txtTitle = (TextBox)e.Item.FindControl("txtTitle");
        TextBox txtDirector = (TextBox)e.Item.FindControl("txtDirector");
        CheckBox chkInTheaters = (CheckBox)e.Item.FindControl("chkInTheaters");
        // 填充sqlDataSource的InsertParameters值
        srcMovies.InsertParameters["Title"].DefaultValue = txtTitle.Text;
        srcMovies.InsertParameters["Director"].DefaultValue = txtDirector.Text;
        srcMovies.InsertParameters["InTheaters"].DefaultValue =
        chkInTheaters.Checked.ToString();
        // Fire the InsertCommand
        srcMovies.Insert();
    }

    /// Delete a movie record
    protected void DeleteMovie(RepeaterCommandEventArgs e)
    {
        // 设置sqlDataSource的DeleteParameters值
        srcMovies.DeleteParameters["Id"].DefaultValue =  Keys[e.Item.ItemIndex].ToString();
        // Fire the DeleteCommand
        srcMovies.Delete();
    }
</script> 

2.Repeater控件之好處

删除数据:

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

protected void btnAddNewRow_Click(object sender, EventArgs e)
{

=== 前台页面

澳门新萄京 8
<asp:Repeater id="rptMovies" DataSourceID="srcMovies" Runat="server"
      OnItemCommand="rptMovies_ItemCommand" OnItemDataBound="rptMovies_ItemDataBound" OnDataBinding="rptMovies_DataBinding">
    <HeaderTemplate>
        <table class="movies">
        <tr> <th>Title</th><th>Director</th><th>In Theaters</th> </tr>
    </HeaderTemplate>
    <ItemTemplate>
        <tr>
            <td><asp:TextBox id="txtTitle" Text='<%#Eval("Title")%>' Runat="server" /></td>           
            <td><asp:TextBox id="txtDirector" Text='<%#Eval("Director")%>' Runat="server" /></td>
            <td><asp:CheckBox id="chkInTheaters" Checked='<%#Eval("InTheaters")%>'Runat="server" /></td>
            <td><asp:LinkButton id="lnkUpdate" CommandName="Update" Text="Update" Runat="server" />
                 | <asp:LinkButton id="lnkDelete" CommandName="Delete" Text="Delete"
                                  OnClientClick="return confirm(‘Are you sure?');" Runat="server" /></td>
        </tr>
    </ItemTemplate>
    <FooterTemplate>
        <tr>
            <td><asp:TextBox id="txtTitle" Runat="server" /></td>
            <td><asp:TextBox id="txtDirector" Runat="server" /></td>
            <td><asp:CheckBox id="chkInTheaters" Runat="server" /></td>
            <td><asp:LinkButton id="lnkInsert" CommandName="Insert" Text="Insert" Runat="server" /></td>
        </tr>
        </table>
    </FooterTemplate>
</asp:Repeater>

<asp:SqlDataSource id="srcMovies" ConnectionString="<%$ ConnectionStrings:Movies %>"
    SelectCommand="SELECT Id,Title,Director,InTheaters FROM Movies"
    UpdateCommand="UPDATE Movies SET Title=@Title,Director=@Director,InTheaters=@InTheaters WHERE Id=@Id"
    InsertCommand="INSERT Movies(Title,Director,InTheaters) VALUES(@Title,@Director,@InTheaters)"
    DeleteCommand="DELETE Movies WHERE Id=@Id" Runat="server">
    <UpdateParameters>
        <asp:Parameter Name="Id" />
        <asp:Parameter Name="Title" />
        <asp:Parameter Name="Director" />
        <asp:Parameter Name="InTheaters" />
    </UpdateParameters>
    <InsertParameters>
        <asp:Parameter Name="Title" />
        <asp:Parameter Name="Director" />
        <asp:Parameter Name="InTheaters" />
    </InsertParameters>
    <DeleteParameters>
        <asp:Parameter Name="Id" />
    </DeleteParameters>
</asp:SqlDataSource>

  笔者們能够随意的定義Table的表頭、表身和表尾。

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

后台代码

//首先,恢复生机数据源

3.Repeater控件一些基礎設定

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

  

DataTable dt = DefineDataTableSchema(hfRptColumns.Value);

  例:以下例子呈现了怎么對Repeater控件進行綁定,并實現在table中實現編輯和立异數據行的操作

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

 代码如下

foreach (RepeaterItem item in rp_List.Items)

html端代碼:

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

复制代码

{

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

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

  string sql = string.Format("select * from person");
        DataTable dt = sqlhelper.helper.ExecuteQuery(sql);
        Repeater1.DataSource = dt;
        Repeater1.DataBind();

DataRow newRow = dt.NewRow();

<table>

启用,禁用:

AspNetpager的使用方法:

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

<tr><th></th>

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

    首先注册<%@ Register Assembly="AspNetPager" Namespace="Wuqi.Webdiyer" TagPrefix="webdiyer" %>

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

<th>用戶ID</th>

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

前台:

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

<th>用戶名</th>

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

  

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

<th>籍貫</th>

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

 代码如下

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

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

复制代码

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

</HeaderTemplate>

  <webdiyer:AspNetPager ID="AspNetPager1" runat="server" CustomInfoHTML="第%CurrentPageIndex%页,共%PageCount%页,每页%PageSize%条"
                FirstPageText="首页" LastPageText="尾页" LayoutType="Table" NextPageText="下一页"
                onpagechanging="AspNetPager1_PageChanging" PageIndexBoxType="DropDownList"
                PagingButtonLayoutType="Span" PrevPageText="上一页" ShowCustomInfoSection="Left"
                ShowPageIndexBox="Always" SubmitButtonText="Go" TextAfterPageIndexBox="页"
                TextBeforePageIndexBox="转到" Width="450px" PageSize="3">
                </webdiyer:AspNetPager>

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

<ItemTemplate>

后台:

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

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

  

dt.Rows.Add;

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

 代码如下

}

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

复制代码

//增添大器晚成行

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

  private void AddPages(Repeater rpt,Wuqi.Webdiyer.AspNetPager anp,DataTable dt)
        {
            PagedDataSource pds = new PagedDataSource();
            pds.AllowPaging = true;
            pds.DataSource = dt.DefaultView;
    
            anp.RecordCount = dt.Rows.Count;//给分页控件钦定当前总和
            pds.PageSize = anp.PageSize;//明确分页,每页有n项
            pds.CurrentPageIndex = anp.CurrentPageIndex - 1;//明显当前页数
    
            rpt.DataSource = pds;//绑定数据源
            rpt.DataBind();
        }
        protected void AspNetPager1_PageChanging(object src, Wuqi.Webdiyer.PageChangingEventArgs e)
        {
            AspNetPager1.CurrentPageIndex = e.NewPageIndex;
            BindPersonData();
        }

DataRow row = dt.NewRow();

<td><%#Eval("userID")%></td>

例子

row["Contentzh"] = "";

<td><%#Eval("username")%></td>

repeater控件动态增加、删除生机勃勃行

row["Contenten"] = "";

<td><%#Eval("birthplace")%></td>

 代码如下

row["photo"] = "";

<td><%Eval("nationality")%></td><tr>

复制代码

row["orderby"] = "0";

</asp:Panel>

<script type="text/javascript">
        var txtEquipmentIdsIDArray = new Array();
        function OpenWindow(clientId, TypeId, ReqNum) {
            var url = "../EquipmentIssue/EquipmentRequestIssue.aspx?TypeId=" TypeId "&ReqNum=" ReqNum;
            var widths = 600;
            var heigths = 450;
            var winPar = window.showModalDialog(url, window, 'dialogWidth=' widths 'px;dialogHeight=' heigths 'px;status=no;center=yes;scroll=no;help:No;');
            if (winPar != undefined) {
                var txtEquipmentIds = document.getElementById(clientId);
                txtEquipmentIds.value = winPar;

row["maxsecond"] = "1";

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

//                //审查批准客户控件中保存发放的EquipmentId
//                var IsExistEquipmentIdsID = false;
//                for (var i = 0; i < txtEquipmentIdsIDArray.length; i ) {
//                    if (txtEquipmentIdsIDArray[i] == clientId) {
//                        IsExistEquipmentIdsID = true;
//                    }
//                }
//                if (IsExistEquipmentIdsID == false) {
//                    txtEquipmentIdsIDArray.push(clientId);
//                }
//                var tempEquipmentId = "";
//                for (var i = 0; i < txtEquipmentIdsIDArray.length; i ) {
//                    tempEquipmentId = tempEquipmentId document.getElementById(txtEquipmentIdsIDArray[i]).value;
//                    var hiddenEquipmentIds = document.getElementById("UC_ApprovalAction1_hfEquipmentIds");
//                    hiddenEquipmentIds.value = tempEquipmentId;
//                }
//                //alert(hiddenEquipmentIds.value);
            }

row["IsHave"] = "未上传";

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

            var tempReturnValue = "";
            var tb_Request = document.getElementById("tb_Request");
            var tr = tb_Request.getElementsByTagName("tr");
            for (var i = 0; i < tr.length; i ) {
                if (tr[i].id != "") {
                    var span_EquRequestItemId = tr[i].getElementsByTagName("span"卡塔尔; //获取申请明细的IDEquRequestItemId
                    var select_ddlStation; //获取使用工位StationId
                    var option = tr[i].getElementsByTagName("select")[1].getElementsByTagName("option");
                    for (var j = 0; j < option.length; j ) {
                        if (option[j].selected)
                        {
                            select_ddlStation = option[j]
                        }
                    }
                    var textarea_EquipmentIds = tr[i].getElementsByTagName("textarea"卡塔尔国; //获取发放的财力号EquipmentNo
                    tempReturnValue = tempReturnValue span_EquRequestItemId[0].innerText ":" select_ddlStation.value ":" textarea_EquipmentIds[0].innerText "|";
                }
            }
            var hiddenEquipmentIds = document.getElementById("UC_ApprovalAction1_hfEquipmentIds");
            hiddenEquipmentIds.value = tempReturnValue;
            //alert(hiddenEquipmentIds.value);
           
        } 
    </script>

row["soundsize"] = "1";

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

Repeater:

dt.Rows.Add;

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

 代码如下

rp_List.DataSource = dt;

<td><%#Eval("userID")%></td>

复制代码

rp_List.DataBind();

<td><%#Eval("username")%></td>

<div id="div_Repeater">
<asp:HiddenField ID="hfRptColumns" runat="server" Value="Guid,EquRequestItemId,EquipmentType,Station,EquipmentNum,EquipmentIds" />
            <table id="tb_Request" cellpadding="1" cellspacing="0" width="100%" style="background-color: #DFE8F6; font-size:12px; padding:10px;">
                <thead>
                    <tr>
                        <th>序号</th>
                        <th>明细编号</th>
                        <th>
                            资金财产连串
                        </th>
                        <th>
                            使用工位
                        </th>
                        <th>
                            申请数量
                        </th>
                        <th>
                            发放的本钱号<font color="red">(资金财产助理馆员填写卡塔尔(英语:State of Qatar)</font>
                        </th>
                    </tr>
                </thead>
                <tbody>
                    <asp:Repeater ID="rptRequest" runat="server" onitemcommand="rptRequest_ItemCommand"
                    onitemdatabound="rptRequest_ItemDataBound">
                        <ItemTemplate>
                            <tr id="tr_Request">
                                <td>
                                    <%# Container.ItemIndex 1 %>
                                    <asp:Label ID="lblGuid" runat="server" Text='<%#Eval("Guid") %>' Visible="false"></asp:Label>
                                </td>
                                <td><asp:Label ID="lblEquRequestItemId" runat="server" Text='<%#Eval("EquRequestItemId") %>'></asp:Label></td>
                                <td>
                                    <asp:DropDownList ID="ddlEquipmentType" runat="server"></asp:DropDownList>
                                    <asp:Label ID="lblEquipmentType" runat="server" Text='<%#Eval("EquipmentType") %>' Visible="false"></asp:Label>
                                </td>
                                <td>
                                    <asp:DropDownList ID="ddlStation" runat="server"></asp:DropDownList>
                                    <asp:Label ID="lblStation" runat="server" Text='<%#Eval("Station") %>' Visible="false"></asp:Label>
                                </td>
                                <td><asp:TextBox ID="txtReqEquipmentNum" runat="server" Text='<%#Eval("EquipmentNum") %>'></asp:TextBox></td>
                                <td><asp:TextBox ID="txtEquipmentIds" runat="server" Text='<%#Eval("EquipmentIds") %>' TextMode="MultiLine"></asp:TextBox></td>
                                <td><asp:Button ID="btnAddRow" runat="server" Text="新扩展风华正茂行" CommandName="add" />
                                    <asp:Button ID="btnDeleteRow" runat="server" Text="删除本行" CommandName="delete" /></td>
                            </tr>
                        </ItemTemplate>
                    </asp:Repeater>
                </tbody>
            </table>
</div>

}

<td><%#Eval("birthplace")%></td>

后台:

/// <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><%Eval("nationality")%></td><tr>

 代码如下

</asp:Panel>

复制代码

</ItemTemplate>

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

<FooterTemplate>

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

</table>

        private void LoadData(string businessNo, DataTable dt)
        {
            string strSql = "select * from EMS_EquipmentRequestItem where BussinessNo = '" businessNo "'";
            DataTable dt_EquipmentRequestItem = DBUtility.DbHelperSQL.Query(strSql).Tables[0];

</FooterTemplate>

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

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

protected void Page_Load(object sender, EventArgs e)
{

            //为第黄金时代行加载一些数码
            DataRow row0 = dt.Rows[0];
            row0["Guid"] = Guid.NewGuid();
            row0["EquRequestItemId"] = "";
            row0["EquipmentType"] = "";
            row0["Station"] = "";
            row0["EquipmentNum"] = "1";//私下认可初步为1
            row0["EquipmentIds"] = "";
        }

if(Page.IsPostBack)

        /// <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(str);
            }
            return 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");

BindData();

                //首先,苏醒数据源
                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);

}

                    if (lblGuid.Text == ((System.Web.UI.WebControls.Label)item.FindControl("lblGuid")).Text)
                    {
                        //增加生龙活虎行
                        DataRow row = dt.NewRow();
                        row["Guid"] = Guid.NewGuid();
                        row["EquipmentType"] = "";
                        row["Station"] = "";
                        row[澳门新萄京,"EquipmentNum"] = "1";//默许起初为1
                        row["EquipmentIds"] = "";
                        dt.Rows.Add(row);
                    }
                }

}

                rptRequest.DataSource = dt;
                rptRequest.DataBind();
            }
            else if (e.CommandName == "delete")
            {
                System.Web.UI.WebControls.Label lblGuid = (System.Web.UI.WebControls.Label)e.Item.FindControl("lblGuid");

 

澳门新萄京:net中Repeater控件用法笔记,控件之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);
                    }
                }

protected void BindData()

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

{

        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;

string sql = "select * from user";

                string sqlstr = @"select distinct b.TypeId,b.EquipmentName '_' b.EquipmentType as 'EquipmentName_EquipmentType'
                                from EMS_EquipmentInfo a
                                join EMS_EquipmentType b on a.TypeId = b.TypeId and b.Status = '1'
                                order by EquipmentName_EquipmentType";
                DataSet ds = DBUtility.DbHelperSQL.Query(sqlstr);
                ddlEquipmentType_temp.DataTextField = "EquipmentName_EquipmentType";
                ddlEquipmentType_temp.DataValueField = "TypeId";
                ddlEquipmentType_temp.DataSource = ds;
                ddlEquipmentType_temp.DataBind();
                ddlEquipmentType_temp.SelectedValue = (e.Item.FindControl("lblEquipmentType") as System.Web.UI.WebControls.Label).Text;

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

                DropDownList ddlStation_temp = e.Item.FindControl("ddlStation") as DropDownList;

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

                string sqlstr2 = @"select NodeId,Line '_' StationName as 'Line_StationName' from V_Stations where status='1' order by Line_StationName";
                DataSet ds2 = DBUtility.DbHelperSQL.Query(sqlstr2);
                ddlStation_temp.DataTextField = "Line_StationName";
                ddlStation_temp.DataValueField = "NodeId";
                ddlStation_temp.DataSource = ds2;
                ddlStation_temp.DataBind();
                ddlStation_temp.SelectedValue = (e.Item.FindControl("lblStation") as System.Web.UI.WebControls.Label).Text;

reportRepeater.DataSource = dt;

                TextBox txtEquIds = e.Item.FindControl("txtEquipmentIds") as TextBox;
                txtEquIds.Attributes.Add("readonly", "true");
              
                if (Request["BusinessNo"] != null)
                {
                    (e.Item.FindControl("btnAddRow") as System.Web.UI.WebControls.Button).Visible = false;
                    (e.Item.FindControl("btnDeleteRow") as System.Web.UI.WebControls.Button).Visible = false;

reportRepeater.DataBind();

                    string businessNo = Request["BusinessNo"].ToString();
                    bool IsApplyUser = Is_ApplyUser(Session["currentUserID"].ToString(), businessNo, "EMS_EquipmentRequest", "Requester"卡塔尔(قطر‎;//是还是不是为申请人本身
                    if (IsApplyUser == true)
                    {
                        string requestStatus = HttpUtility.UrlDecode(Request["RequestStatus"].ToString(卡塔尔(قطر‎, System.Text.Encoding.UTF8卡塔尔国;//申请单的眼下事态
                        if (requestStatus == "草稿" || requestStatus == "退回")
                        {
                            (e.Item.FindControl("btnAddRow") as System.Web.UI.WebControls.Button).Visible = true;
                            (e.Item.FindControl("btnDeleteRow") as System.Web.UI.WebControls.Button).Visible = true;
                        }
                    }
                    else
                    {
                        bool IsCurrentAppprovaler = Is_CurrentAppprovaler(Session["currentUserID"].ToString(卡塔尔(قطر‎, businessNo卡塔尔(قطر‎;//是不是为眼下能做审批的人
                        if (IsCurrentAppprovaler == true)
                        {
                            string sql = " SELECT TOP 1 LayerName from EMS_Approvaler where BussinessNo='" businessNo "' "
                                        " AND ApprovalStatus='N' ORDER BY AppSequence ";
                            DataTable dt = DBUtility.DbHelperSQL.Query(sql).Tables[0];

}

                            if (dt.Rows.Count != 0 && dt.Rows[0]["LayerName"].ToString(卡塔尔(英语:State of Qatar) == "资金财产管理员"卡塔尔国
                            {
                                string ReqNum = (e.Item.FindControl("txtReqEquipmentNum") as TextBox).Text.Trim();
                                txtEquIds.Attributes.Add("onclick", "OpenWindow('" txtEquIds.ClientID "','" ddlEquipmentType_temp.SelectedValue "','" ReqNum "')");
                            }
                        }
                    }
 
                }

protected void reportRepeater_ItemCommand(object source, RepeaterCommandEventArgs e)

            }
        }

{

 

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

您只怕感兴趣的篇章

{

  • 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控件并响应单击操作的方式

//更新數據庫

break;

}

case "CANCEL":

{

id="";

break;

}

case "DELETE":

{

//從數據庫刪除

break;

}

//數據綁定

BindData();

}

protected void reportRepeater_ItemDataBound(object sender, RepeaterItem伊芙ntArgs e卡塔尔国//Item綁定時能够在那做一些操作

{

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

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

}

}

本文由澳门新萄京发布于www.澳门新萄京赌场,转载请注明出处:澳门新萄京:net中Repeater控件用法笔记,控件之

上一篇:数据类型,Python学习笔记 下一篇:没有了
猜你喜欢
热门排行
精彩图文