asp.net mvc use Easyui's DataGrid multi-Select Submit Save Tutorial _ Practical Tips

Source: Internet
Author: User
Tags bulk insert
Need to implement Easyui DataGrid component join Select CheckBox column, and submit background bulk added functionality, the page code is as follows:
Copy Code code as follows:

<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 (' Save failed! ');
}
}, ' json ');
}
</script>
<div style= "width:100%; height:100% ">
<table id= "Selectgoods-grid" class= "Easyui-datagrid" true "fit=" #tlb_selectgoods_search "toolbar=" 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= "editor=" {type: ' Validatebox ', Options:{required:true}} "> Product name </th>
<th field= "chemistry" width= "editor=" {type: ' Validatebox ', Options:{required:true}} "> Chemical index </th>
<th field= "Physical" width= "editor=" {type: ' Validatebox ', Options:{required:true}} "> Physical index </th>
<th field= "Partner_name" width= "editor=" {type: ' Validatebox ', Options:{required:true}} "> Cooperation status </th>
</tr>
</thead>
</table>
<div id= "Tlb_selectgoods_search" >
Product Name: <input name= "keywords" id= "selectgoods-keywords" class= "Easyui-searchbox/><a" "href=" Easyui-linkbutton "iconcls=" Icon-save "plain=" true "onclick=" Javascript:saveselectgoods () "> Save </a>
</div>
</div>

The controller code for ASP.net MVC is as follows:
Copy Code code as follows:

<summary>
Multiple selection items added
</summary>
<param name= "Supplier" > Suppliers id</param>
<returns></returns>
Public ActionResult Selectgoods (string supplier)
{
viewdata["Supplier"] = supplier;
return View ();
}
<summary>
Save bulk-Added product information
</summary>
<param name= "Checks" > Selected products id</param>
<param name= "Supplier" > Supplier name </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;
Assembling XML
String ids=communion.stringhelper.buildxmlid (checks);
Goods. goods_id = -1;//Label BULK INSERT
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. save<suppliergoods> (goods);
if (goods. Identifier = 0)
{
Goods. Identifier = ID;
}
Result. Data = true;
return result;
}
catch (Exception e)
{
return result;
}
}

Stored procedures use XML variables to bulk add to the collection of IDs of incoming XML types to the database, stored procedure code as follows:
Copy Code code as follows:

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 (=null),
@Physical nvarchar (=null),
@Chemistry nvarchar (=null),
@Customers nvarchar (=null),
@Equipment nvarchar (=null),
@Note nvarchar (MAX) =null,
@Detail_Params nvarchar (=null)
As
IF @Goods_ID =-1
BEGIN
--BULK INSERT Merchandise
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
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.