工作中出现了一点问题,repeater中添加input/select等标签时,后台需要取值使用,但是不能添加runat="server",如果加上runat="server"后点击分页按钮,repeater中将显示整个页面内容截图,所以去除runat="server" 代码如下:
1、标签:<input type="text" id="txt_ReceiveGift_<%#Eval("Id") %>" value="<%#Eval("ReceiveGift")%>" style=" 55px;" /> 例如其中一个
2、js:
function savetd(id)
{
var sel_type=$("#sel_type_"+id).val();
var sel_Ytype=$("#sel_Ytype_"+id).val();
var txt_ReceiveGift=$("#txt_ReceiveGift_"+id).val();
var txt_Receipt=$("#txt_Receipt_"+id).val();
var txt_Invoice=$("#txt_Invoice_"+id).val();
//var lblNowTime=$("#lblNowTime_"+id).val();
if(txt_ReceiveGift=="")
{
art.dialog("请输入领取礼品金额");
return;
}
if(txt_Receipt=="")
{
art.dialog("请输入收据单号");
return;
}
if(txt_Invoice=="")
{
art.dialog("请输入发票单号");
return;
}
var DataCache = {};
DataCache.sel_type=sel_type;
DataCache.sel_Ytype=sel_Ytype;
DataCache.txt_ReceiveGift=txt_ReceiveGift;
DataCache.txt_Receipt=txt_Receipt;
DataCache.txt_Invoice=txt_Invoice;
DataCache.lblusername=lblusername;
DataCache.id=id;
var lblusername=$("#<%=HidPid.ClientID%>").val();
var lblNowTime=$("#<%=HidTime.ClientID%>").val();
DataCache.lblusername=lblusername;
DataCache.lblNowTime=lblNowTime;
var result = Invoke("ParkingFee.aspx/CreateInvoice", DataCache);
if(result=="OK")
{
art.dialog("保存成功");
window.location.href="ParkingFee.aspx";
}
}
3、 }
[WebMethod]
public static string CreateInvoice(string sel_type, string txt_ReceiveGift, string txt_Receipt, string txt_Invoice, string lblusername,string sel_Ytype,DateTime lblNowTime,string id)
{
if ("0".Equals(id))
{
return "error";
}
ETCP.Model.ParkingFee ParkingFeeModel = new Model.ParkingFee();
ParkingFeeService parkingfeeservice=new ParkingFeeService();
ParkingFeeModel.MoneyType = sel_type;
ParkingFeeModel.Type = sel_Ytype;
ParkingFeeModel.ReceiveGift = txt_ReceiveGift;
ParkingFeeModel.Receipt = txt_Receipt;
ParkingFeeModel.Invoice = txt_Invoice;
ParkingFeeModel.TransferName = lblusername;
//lblNowTime = DateTime.Now;
ParkingFeeModel.NowTime = lblNowTime;
ParkingFeeModel.Id = Convert.ToInt16(id);
ParkingFeeModel.Received = 1;
parkingfeeservice.UpdateParkingFee(ParkingFeeModel);
return "OK";
}
4、 <asp:HiddenField ID="HidPid" runat="server" /><asp:HiddenField ID="HidTime" runat="server" />其中部分值不能直接取到,改用隐藏控件获取值
5、select绑定数据库字段
<select id="sel_type_<%#Eval("Id") %>" style=" 50px;">
<option value="1"<%#Eval("MoneyType").ToString()=="1"?"selected=\"selected\"":"" %>>测试1</option>
<option value="2" <%#Eval("MoneyType").ToString()=="2"?"selected=\"selected\"":"" %>>测试2</option>
<option value="3" <%#Eval("MoneyType").ToString()=="3"?"selected=\"selected\"":"" %>>测试3</option></select>
6、绑定按钮 <%#Eval("IsSave")%> 如果为1不显示 否则显示保存按钮
IsSave = o.Received == 1 ? "" : "<input type='button' onclick='savetd("+ o.Id+")' value='保存'/>",
7、对一些字段进行统计
Dictionary<string, ETCP.Model.ParkingFee> dic = new Dictionary<string, Model.ParkingFee>(); //键值方法
foreach (var item1 in list)
{
Sum1 += item1.Money; //统计字段总和
Sum3 += decimal.Parse(item1.ReceiveGift); //统计字段总和
if (!dic.ContainsKey(item1.Owner))
dic.Add(item1.Owner, item1); //过滤方法 显示不重复
}
Sum4 = list.Count; //显示总和长度
Sum2 = dic.Count; //显示过滤后总和长度