(一).net中使用Repeater绑定数据,并使用repeater循环出的两个值,赋给repeater中的div的value值。详细如下:
前端.net代码:
<div class="wytz_xmlb_nr clear"><asp:Repeater ID="RpBidsList" runat="server"><ItemTemplate><div class="xmlb_list_tiao"><span class="list_tiao_pic"><a href="#"><img src="../images/index_pic_74.jpg" width="77" height="77" /></a></span><div class="list_tiao_pic_nr"><span class="list_tiao_pic_nr_bt"><%#Eval("SysBid_Title")%></span><div class="list_tiao_pic_nr_jies"><div id='p<%#Eval("SysBid_ID")%>' class="easyui-progressbar" style="width:153px; height:10px;"></div>当前可投金额:<%#qt.hfd_p2p.Common.Utils.ChangedStr((Decimal.Parse(Eval("SysBid_Floor").ToString())-Decimal.Parse(Eval("SysBid_Fund").ToString())).ToString())%>元</div><input type="hidden" value="<%#Eval("SysBid_Fund")%>" id='fund<%#Eval("SysBid_ID")%>' /><input type="hidden" value="<%#Eval("SysBid_Floor")%>" id='floor<%#Eval("SysBid_ID")%>' /></div><div class="list_tiao_bqze"><span class="list_tiao_bqze_bt">本期借款总额</span><span class="list_tiao_bqze_nr"><%#qt.hfd_p2p.Common.Utils.ChangedStr(Eval("SysBid_Floor").ToString())%>元</span></div><div class="list_tiao_nhll"><span class="list_tiao_bqze_bt">年化利率</span><span class="list_tiao_bqze_nr"><%#Eval("SysBid_Ratio")%>%</span></div><div class="list_tiao_tzzq"><span class="list_tiao_bqze_bt">投资周期</span><span class="list_tiao_bqze_nr"><%#Eval("SysBid_CheckCycle")%><%#GetUnit((int)Eval("SysBid_CheckCycleUnit"))%></span></div><div class="list_tiao_touzi"><a href="InvestDetail.aspx?SysBid_ID=<%#Eval("SysBid_ID")%>">马上投资</a></div></div></ItemTemplate></asp:Repeater><div class="fenye"><div id="PageContent" runat="server"></div></div></div>
前端js代码:循环每个Itemtemplate中的id为found和floor的值,并计算出数组复制给id为p的div
window.onload = function () {var values;$("div .xmlb_list_tiao").each(function (index, element) {var fund = $(element).find("input[type='hidden']").eq(0).val();var floor = $(element).find("input[type='hidden']").eq(1).val();var bidProgress = fund / floor * 100.00;bidProgress = Math.round(parseFloat(bidProgress) * 100) / 100;$(element).find("div .easyui-progressbar.progressbar").progressbar({ value: bidProgress });//alert(bidProgress); });}
注意javasript中each的用法~
展示效果如下图,计算出每条数据的进度条的值
(二)Repeater中全选功能的实现。效果图如下:
如上图所示:点击全选按钮列表中的checkbox全部选中,全选变为取消。点击取消按钮,列表中的复选框则均不选择。
首先,前端aspx页面代码:
全选按钮:
<li><a class="all" href="javascript:;" οnclick="checkAll(this);"><i></i><span>全选</span></a></li>
列表复选框:
<td align="center"><asp:CheckBox ID="chkId" CssClass="checkall" runat="server" style="vertical-align:middle;" /><asp:HiddenField ID="hidId" Value='<%#Eval("SysBid_ID")%>' runat="server" /></td>
使用javascript方法实现全选方法:
//全选取消按钮函数
function checkAll(chkobj) {if ($(chkobj).text() == "全选") {$(chkobj).children("span").text("取消");$(".checkall input:enabled").prop("checked", true);} else {$(chkobj).children("span").text("全选");$(".checkall input:enabled").prop("checked", false);}
}
(三)Repeater中删除列表数据一条或多条(批量与否)
前端aspx代码:
删除按钮
<li><asp:LinkButton ID="btnDelete" runat="server" CssClass="del" OnClientClick="return ExePostBack('btnDelete');" οnclick="btnDelete_Click"><i></i><span>删除</span></asp:LinkButton></li>
选择要删除的数据,一条或多条:
<td align="center"><asp:CheckBox ID="chkId" CssClass="checkall" runat="server" style="vertical-align:middle;" /><asp:HiddenField ID="hidId" Value='<%#Eval("SysBid_ID")%>' runat="server" />
</td>
后台aspx.cs方法
protected void btnDelete_Click ( object sender, EventArgs e ){int sucCount = 0;int errorCount = 0;BLL.SystemBids bll = new BLL.SystemBids( );for ( int i = 0 ; i < rptList.Items.Count ; i++ ){int id = Convert.ToInt32( ( ( HiddenField )rptList.Items[ i ].FindControl( "hidId" ) ).Value );CheckBox cb = ( CheckBox )rptList.Items[ i ].FindControl( "chkId" );if ( cb.Checked ){if ( bll.Delete( id ) ){sucCount += 1;}else{errorCount += 1;}}}AddAdminLog( DTEnums.ActionEnum.Delete.ToString( ), "删除系统标的" + sucCount + "条,失败" + errorCount + "条" ); //记录日志JscriptMsg( "删除成功" + sucCount + "条,失败" + errorCount + "条!",Utils.CombUrlTxt( "bids_list.aspx", "bidcate_id={0}&keywords={1}", this.bidcate_id.ToString( ), this.keywords ), "Success" );}
(四)1.Repeater数据列表中最后一列为操作,操作显示的动作可以是修改或已修改。2.根据选中行的id删除此行数据
1.修改和已修改均可以显示,其visible可设定为某一个状态值
例如:aspx前端代码:
<td width="10%" align="center"><asp:LinkButton ID="lbaward" runat="server" CommandName="Updateaward" CommandArgument='<%#Eval("id")%>' Visible='<%#int.Parse(Eval("is_lock").ToString())==0? true : false %>'>抽奖</asp:LinkButton><asp:LinkButton ID="lbed" runat="server" Visible='<%#int.Parse(Eval("is_lock").ToString()) == 1 ? true : false %>' >已中奖</asp:LinkButton>
</td>
2.根据选中行的id删除此行的数据
前端aspx代码如上1: 添加CommandName,添加CommandArgument的值
protected void rptList_ItemCommand(object source, RepeaterCommandEventArgs e){if (e.CommandName == "Updateaward"){//当前选中行的idint id = int.Parse(e.CommandArgument.ToString());Model.navigation nmodel = nbll.GetModel(id);if (nbll.UpdateField(id, "is_lock=1 , remark='中奖时间为:" + DateTime.Now.ToString() + "'")){JscriptMsg("设置中奖成功!", Request.Url.AbsoluteUri.ToString(), "success");}else{JscriptMsg("设置中奖失败!", Request.Url.AbsoluteUri.ToString(), "fail");}}}