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

转发自互联网-原网址【

大家大概都对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页面中运用3个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>

 

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控件?

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>

  關於把從數據庫讀取的數據綁定到前台頁面,我們可以运用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();
}
}
}

复制代码

后台代码:

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

  作者們能够私行的定義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>
net中Repeater控件用法笔记,Repeater动态添加行。<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”>(资金财产管理员填写)</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#金沙注册送58,後端代碼:

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

 

                //首先,苏醒数据源
                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() == “资金财产管理员”)
                            {
                                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,
RepeaterItemEventArgs 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;
}

}

}

相关文章

网站地图xml地图