佳木斯湛栽影视文化发展公司

主頁(yè) > 知識(shí)庫(kù) > ASP.NET MVC使用EasyUI的datagrid多選提交保存教程

ASP.NET MVC使用EasyUI的datagrid多選提交保存教程

熱門標(biāo)簽:團(tuán)購(gòu)網(wǎng)站 服務(wù)器配置 Mysql連接數(shù)設(shè)置 電子圍欄 科大訊飛語(yǔ)音識(shí)別系統(tǒng) 阿里云 Linux服務(wù)器 銀行業(yè)務(wù)
需要實(shí)現(xiàn)EasyUI的datagrid組件加入選擇checkbox列,并提交后臺(tái)批量添加的功能,頁(yè)面代碼如下:
復(fù)制代碼 代碼如下:

script language="javascript" type="text/javascript">
$(function() {
//searchbox
$('#selectgoods-keywords').searchbox({
searcher: function(val, name) {
searchInfo(val);
}
});
//datagrid
$('#selectgoods-grid').datagrid({
url: '/Goods/List',
pageNumber: 1,
pageSize: 20,
pageList: [20, 40, 60, 80, 100]
});
//form
});
function searchInfo(val){
// var keytype=$('#keyType').combobox('getValue');
var keytype = 'Goods_Name';
var keywords = val;
$('#selectgoods-grid').datagrid('reload', { keytype: keytype, keywords: keywords });
}
function saveSelectGoods() {
var ids = [];
var rows = $('#selectgoods-grid').datagrid('getSelections');
for (var i = 0; i rows.length; i++) {
ids.push(rows[i].Identifier);
}
var selectsupplier = '%=ViewData["supplier"] %>';
$.post('/SupplierGoods/SaveSelect', { supplier: selectsupplier, checks: ids.join(',') }, function(data) {
if (data) {
$('#goodslist-grid').datagrid('reload');
$('#goodsInfo-window').window('close');
} else {
alert('保存失敗!');
}
}, 'json');
}
/script>
div style="width:100%; height:100%">
table id="selectgoods-grid" class="easyui-datagrid" fit="true" toolbar="#tlb_selectgoods_search" pagination="true"
rownumbers="true" fitColumns="true" idField="Identifier">
thead>
tr>
th field="ck" checkbox="true">/th>
th field="Identifier" hidden="true" width="0" editor="text">Id/th>
th field="Goods_Name" width="100" editor="{type:'validatebox',options:{required:true}}">商品名稱/th>
th field="Chemistry" width="100" editor="{type:'validatebox',options:{required:true}}">化學(xué)指標(biāo)/th>
th field="Physical" width="100" editor="{type:'validatebox',options:{required:true}}">物理指標(biāo)/th>
th field="Partner_Name" width="50" editor="{type:'validatebox',options:{required:true}}">合作狀態(tài)/th>
/tr>
/thead>
/table>
div id="tlb_selectgoods_search">
商品名稱:input name="keywords" id="selectgoods-keywords" class="easyui-searchbox" />a href="#" class="easyui-linkbutton" iconCls="icon-save" plain="true" onclick="javascript:saveSelectGoods()">保存/a>
/div>
/div>

ASP.NET MVC的Controller代碼如下:
復(fù)制代碼 代碼如下:

/// summary>
/// 多選商品添加
/// /summary>
/// param name="supplier">供貨商ID/param>
/// returns>/returns>
public ActionResult SelectGoods(string supplier)
{
ViewData["supplier"] = supplier;
return View();
}
/// summary>
/// 保存批量添加的產(chǎn)品信息
/// /summary>
/// param name="checks">選中的商品ID/param>
/// param name="supplier">供貨商名稱/param>
/// returns>/returns>
public JsonResult SaveSelect(string checks, string supplier)
{
JsonResult result = new JsonResult();
result.Data = false;
try
{
if (String.IsNullOrEmpty(supplier))
return result;
SupplierGoods goods = new SupplierGoods();
goods.Identifier = 0;
//拼裝xml
String ids=Communion.StringHelper.BuildXmlID(checks);
goods.Goods_ID = -1;//標(biāo)示批量插入
goods.Note = ids;
goods.Month_Output = Convert.ToDouble(String.IsNullOrEmpty(this.ReadFromRequest("Month_Output")) ? "0" : this.ReadFromRequest("Month_Output"));
goods.Supplier_ID = Convert.ToInt32(supplier);
goods.Create_Date = DateTime.Now;
goods.Customers = this.ReadFromRequest("Customers");
goods.Equipment = this.ReadFromRequest("Equipment");
goods.Detail_Params = this.ReadFromRequest("Detail_Params");
goods.IsDefault = Convert.ToInt32(String.IsNullOrEmpty(this.ReadFromRequest("IsDefault")) ? "0" : this.ReadFromRequest("IsDefault"));
Business business = new BusinessLogic();
int id = business.SaveSupplierGoods>(goods);
if (goods.Identifier == 0)
{
goods.Identifier = id;
}
result.Data = true;
return result;
}
catch (Exception e)
{
return result;
}
}

存儲(chǔ)過(guò)程利用xml變量對(duì)傳入的xml類型的ID集合進(jìn)行批量添加保存到數(shù)據(jù)庫(kù)中,存儲(chǔ)過(guò)程代碼如下:
復(fù)制代碼 代碼如下:

ALTER PROCEDURE [dbo].[View_SupplierGoodsCreate]
@Identifier int,
@Supplier_ID int,
@Goods_ID int,
@isDefault int,
@Create_Date datetime,
@Month_Output float(8),
@Goods_Name nvarchar(400)=NULL,
@Physical nvarchar(400)=NULL,
@Chemistry nvarchar(400)=NULL,
@Customers nvarchar(400)=NULL,
@Equipment nvarchar(400)=NULL,
@Note nvarchar(MAX)=NULL,
@Detail_Params nvarchar(400)=NULL
AS
IF @Goods_ID=-1
BEGIN
--批量插入商品
DECLARE @xml xml
SET @xml=@Note
INSERT INTO Supplier_Goods(Supplier_ID,Goods_ID,Create_Date,Month_Output,Customers,Equipment,Note,isdefault,Detail_Params)
SELECT @Supplier_ID,identifier,@Create_Date,0,null,null,null,0,null
FROM Base_Goods
WHERE
Identifier in (Select
T.ID.value('.', 'int') As ID
From
@xml.nodes('/XML/ID') as T(ID)) and Identifier not in (select goods_id from Supplier_Goods where Supplier_ID=@Supplier_ID)
SET @Identifier=@Goods_ID
END
您可能感興趣的文章:
  • Easyui和zTree兩種方式分別實(shí)現(xiàn)樹形下拉框
  • jQuery使用EasyUi實(shí)現(xiàn)三級(jí)聯(lián)動(dòng)下拉框效果
  • Jquery Easyui自定義下拉框組件使用詳解(21)
  • jQuery+easyui中的combobox實(shí)現(xiàn)下拉框特效
  • EasyUI實(shí)現(xiàn)下拉框多選功能

標(biāo)簽:廣元 江蘇 衡水 蚌埠 大理 萍鄉(xiāng) 棗莊 衢州

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《ASP.NET MVC使用EasyUI的datagrid多選提交保存教程》,本文關(guān)鍵詞  ;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問(wèn)題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無(wú)關(guān)。
  • 相關(guān)文章
  • 收縮
    • 微信客服
    • 微信二維碼
    • 電話咨詢

    • 400-1100-266
    鲜城| 教育| 天等县| 竹山县| 公安县| 康平县| 宝山区| 安国市| 全椒县| 酒泉市| 桂林市| 涿州市| 永川市| 宣城市| 剑河县| 玛纳斯县| 拜城县| 丰县| 贞丰县| 漯河市| 宁武县| 建水县| 宁陕县| 松滋市| 东光县| 马龙县| 咸阳市| 绥化市| 从江县| 斗六市| 桃源县| 来宾市| 新兴县| 东丰县| 奉化市| 宁化县| 永清县| 凤阳县| 长宁区| 疏附县| 河间市|