最近一直很忙,前几天写完一个复选框保存repeater中的一行数据,代码如下:
1、 <select id="invoiceType" runat="server" name="D1"> </select> select下拉框 ,保存类型显示
2、 <input type="checkbox" name="cbType" id="<%#Eval("id") %>"> repeater首行的checkbox按钮
实现功能:当你选择复选框后,保存下拉框中与当前选择行的数据内容
前台页面js代码:
function chk()
{
var valuelist = "";
$("input[name='cbType']:checked").each(function()
{
valuelist+=$(this).attr('id')+",";
});
if (valuelist.length > 0)
{
valuelist = valuelist.substring(0, valuelist.length - 1);
var type=$("#<%=invoiceType.ClientID%>").val();
}
var DataCache = {};
DataCache.cbTypelist=valuelist;
DataCache.invoiceType=type;
var HidPid=$("#<%=HidPid.ClientID%>").val();
DataCache.Pid=HidPid;
var result = Invoke("CarOwnerSelectPageWhite.aspx/CreateInvoice", DataCache);
if(result=="OK")
{
window.location.href="ReaderWhiteList.aspx";
}
}
后台代码:
[WebMethod]
public static string CreateInvoice(string cbTypelist,int invoiceType, int Pid)
{
ReaderWhiteListService readerwhiteservice = new ReaderWhiteListService();
ETCP.Model.ReaderWhiteList list = new Model.ReaderWhiteList();
string[] arg = cbTypelist.Split(','); //复选框
for (int i = 0; i < arg.Length; i++)
{
list.OwnerId = int.Parse(arg[i]);
list.ReaderType = invoiceType;
list.ParkingId = Pid;
readerwhiteservice.InsertReaderWhiteList(list);
}
return "OK";
}