JqGrid: Add,Edit,Del in asp.net
https://github.com/1rosehip/jplist
https://github.com/free-jqgrid/jqGrid
https://plugins.jquery.com/tag/pagination/
https://dotnetsourcedileep.codeplex.com/
/// https://sql2mongo.codeplex.com/
/// https://forums.asp.net/t/1629287.aspx?serverside+code+for+Add+Edit+Del+in+jQGrid
/// https://forums.asp.net/t/1627666.aspx?Edit+Add+Del+in+Jqgrid
/// http://trirand.net/examples/grid/editing_data/edit_add_delete/default.aspx
/// http://www.trirand.com/blog/?page_id=6
/// https://jqgridaspnetmvc.codeplex.com/
/// https://github.com/tpeczek/Lib.AspNetCore.Mvc.JqGrid
/// https://jqmvcgrid.codeplex.com/
/// http://jqgridaspnetmvc.codeplex.com/
/// https://mvccrud.codeplex.com/
/// http://www.trirand.net/download.aspx
/// https://dotnetsourcedileep.codeplex.com/
http://www.c-sharpcorner.com/uploadfile/rahul4_saxena/jqgrid-in-asp-net-c-sharp/
https://github.com/tonytomov/jqGrid
sql:
--jQGridDemo AdventureWorks2012
CREATE TABLE Employee
(
_id VARCHAR(100),
FirstName NVARCHAR(100),
LastName NVARCHAR(100),
LastSSN NVARCHAR(100),
Department NVARCHAR(100),
Age INT,
Salary NVARCHAR(100),
[Address] NVARCHAR(100),
MaritalStatus NVARCHAR(100)
)
GO SELECT * FROM dbo.Employee
GO INSERT dbo.Employee
( _id ,
FirstName ,
LastName ,
LastSSN ,
Department ,
Age ,
Salary ,
Address ,
MaritalStatus
)
VALUES ( '1' , -- _id - varchar(100)
N'du' , -- FirstName - nvarchar(100)
N'geovindu' , -- LastName - nvarchar(100)
N'N0002' , -- LastSSN - nvarchar(100)
N'IT' , -- Department - nvarchar(100)
40 , -- Age - int
N'40000' , -- Salary - nvarchar(100)
N'SZ' , -- Address - nvarchar(100)
N'1' -- MaritalStatus - nvarchar(100)
)
GO INSERT dbo.Employee
( _id ,
FirstName ,
LastName ,
LastSSN ,
Department ,
Age ,
Salary ,
Address ,
MaritalStatus
)
VALUES ( '2' , -- _id - varchar(100)
N'涂' , -- FirstName - nvarchar(100)
N'聚文' , -- LastName - nvarchar(100)
N'N0001' , -- LastSSN - nvarchar(100)
N'HR' , -- Department - nvarchar(100)
40 , -- Age - int
N'80000' , -- Salary - nvarchar(100)
N'SZ' , -- Address - nvarchar(100)
N'2' -- MaritalStatus - nvarchar(100)
)
GO INSERT dbo.Employee
( _id ,
FirstName ,
LastName ,
LastSSN ,
Department ,
Age ,
Salary ,
Address ,
MaritalStatus
)
VALUES ( '3' , -- _id - varchar(100)
N'涂' , -- FirstName - nvarchar(100)
N'斯博' , -- LastName - nvarchar(100)
N'N0003' , -- LastSSN - nvarchar(100)
N'HR' , -- Department - nvarchar(100)
10 , -- Age - int
N'80000' , -- Salary - nvarchar(100)
N'SZ' , -- Address - nvarchar(100)
N'3' -- MaritalStatus - nvarchar(100)
)
GO
Default.aspx:
<link href="~/Styles/Site.css" rel="stylesheet" type="text/css" />
<script src="JQGridReq/jquery-1.9.0.min.js" type="text/javascript"></script>
<link href="JQGridReq/jquery-ui-1.9.2.custom.css" rel="stylesheet" type="text/css" />
<script src="JQGridReq/jquery.jqGrid.js" type="text/javascript"></script>
<link href="JQGridReq/ui.jqgrid.css" rel="stylesheet" type="text/css" />
<script src="JQGridReq/grid.locale-cn.js" type="text/javascript"></script> <h2>
Welcome To Kodoths JQGrid Demo
</h2>
<table id="jQGridDemo">
</table>
<div id="jQGridDemoPager">
</div>
<script type="text/javascript">
jQuery("#jQGridDemo").jqGrid({
url: 'JQGridHandler.ashx',
datatype: "json",
height:500,
colNames: ['Id', 'First Name', 'Last Name', 'Last 4 SSN', 'Department', 'Age', 'Salary', "Address", 'Marital Status'], //名称
colModel: [
{ name: '_id', index: '_id', width: 20, stype: 'text' },
{ name: 'FirstName', index: 'FirstName', width: 150, stype: 'text', sortable: true, editable: true },
{ name: 'LastName', index: 'LastName', width: 150, editable: true },
{ name: 'LastSSN', index: 'LastSSN', width: 60, editable: true },
{ name: 'Department', index: 'Department', width: 80, align: "right", editable: true },
{ name: 'Age', index: 'Age', width: 40, align: "right", editable: true },
{ name: 'Salary', index: 'Salary', width: 80, align: "right", editable: true },
{ name: 'Address', index: 'Address', width: 150, sortable: false, editable: true },
{ name: 'MaritalStatus', index: 'MaritalStatus', width: 100, sortable: false, editable: true }
],
rowNum: 10,
mtype: 'GET',
loadonce: true,
rowList: [10, 20, 30],
pager: '#jQGridDemoPager',
sortname: '_id',
viewrecords: true,
sortorder: 'desc',
caption: "List Employee Details 客户列表",
editurl: 'JQGridHandler.ashx' //http://localhost:58404/
}); $('#jQGridDemo').jqGrid('navGrid', '#jQGridDemoPager',
{
edit: true,
add: true,
del: true,
search: true,
searchtext: "Search",
addtext: "Add",
edittext: "Edit",
deltext: "Delete"
},
{ //EDIT
// height: 300,
// width: 400,
// top: 50,
// left: 100,
// dataheight: 280,
closeOnEscape: true, //Closes the popup on pressing escape key
reloadAfterSubmit: true,
drag: true,
afterSubmit: function (response, postdata) {
if (response.responseText == "") { $(this).jqGrid('setGridParam', { datatype: 'json' }).trigger('reloadGrid'); //Reloads the grid after edit
return [true, '']
}
else {
$(this).jqGrid('setGridParam', { datatype: 'json' }).trigger('reloadGrid'); //Reloads the grid after edit
return [false, response.responseText]//Captures and displays the response text on th Edit window
}
},
editData: {
EmpId: function () {
var sel_id = $('#jQGridDemo').jqGrid('getGridParam', 'selrow');
var value = $('#jQGridDemo').jqGrid('getCell', sel_id, '_id');
return value;
}
}
},
{
closeAfterAdd: true, //Closes the add window after add
afterSubmit: function (response, postdata) {
if (response.responseText == "") { $(this).jqGrid('setGridParam', { datatype: 'json' }).trigger('reloadGrid')//Reloads the grid after Add
return [true, '']
}
else {
$(this).jqGrid('setGridParam', { datatype: 'json' }).trigger('reloadGrid')//Reloads the grid after Add
return [false, response.responseText]
}
}
},
{ //DELETE
closeOnEscape: true,
closeAfterDelete: true,
reloadAfterSubmit: true,
closeOnEscape: true,
drag: true,
afterSubmit: function (response, postdata) {
if (response.responseText == "") { $("#jQGridDemo").trigger("reloadGrid", [{ current: true}]);
return [false, response.responseText]
}
else {
$(this).jqGrid('setGridParam', { datatype: 'json' }).trigger('reloadGrid');
return [true, response.responseText]
}
},
delData: {
EmpId: function () {
var sel_id = $('#jQGridDemo').jqGrid('getGridParam', 'selrow');
var value = $('#jQGridDemo').jqGrid('getCell', sel_id, '_id');
return value;
}
}
},
{//SEARCH
closeOnEscape: true }
); </script>
JQGridHandler.ashx:
public class JQGridHandler : IHttpHandler
{
/// <summary>
///
/// </summary>
/// <param name="context"></param>
public void ProcessRequest(HttpContext context)
{
System.Collections.Specialized.NameValueCollection forms = context.Request.Form;
string strOperation = forms.Get("oper"); MONGOConnect objMC = new MONGOConnect();//Helper Class
var collectionEmployee = objMC.GetMongoCollection("Employee");//Gets Employee Collection List<Employee> emy = new List<Employee>();
//Employee ep = new Employee();
//ep._id = "1";
//ep.Address = "sz";
//ep.Age = 40;
//ep.Department = "it";
//ep.FirstName = "du";
//ep.LastName = "geovin";
//ep.LastSSN = "N0001";
//ep.MaritalStatus = "1";
//ep.Salary = "4000";
//emy.Add(ep);
//ep = new Employee();
//ep._id = "2";
//ep.Address = "深圳";
//ep.Age = 40;
//ep.Department = "人事部";
//ep.FirstName = "涂";
//ep.LastName = "涂聚文";
//ep.LastSSN = "N0002";
//ep.MaritalStatus = "1";
//ep.Salary = "8000";
//emy.Add(ep);
emy = getList(); string strResponse = string.Empty;
//查询
if (strOperation == null)
{
//oper = null which means its first load.
var jsonSerializer = new JavaScriptSerializer();
context.Response.Write(jsonSerializer.Serialize(emy));//collectionEmployee.AsQueryable<Employee>().ToList<Employee>() }
else if (strOperation == "del") //删除
{
var query = Query.EQ("_id", forms.Get("EmpId").ToString());
string de = forms.Get("EmpId").ToString();
//collectionEmployee.Remove(query);
strResponse = "Employee record successfully removed:"+de;
context.Response.Write(strResponse);
}
else
{
string strOut=string.Empty;
AddEdit(forms, collectionEmployee, out strOut);
context.Response.Write(strOut);
} } public bool IsReusable
{
get
{
return false;
}
}
/// <summary>
///
/// </summary>
/// <returns></returns>
private List<Employee> getList()
{
List<Employee> users = new List<Employee>();
string connectionString = @"Data Source=GEOVINDU; Initial Catalog=AdventureWorks2012; User ID=sa; Password=geovindu";
using (SqlConnection connection = new SqlConnection(connectionString))
{
using (SqlCommand command = new SqlCommand())
{
command.Connection = connection;
command.CommandText = "SELECT * FROM dbo.Employee";
command.CommandType = CommandType.Text;
connection.Open();
using (SqlDataReader dataReader = command.ExecuteReader())
{
Employee user;
while (dataReader.Read())
{
user = new Employee();
user._id = Convert.ToString(dataReader["_id"]);
user.Address = Convert.ToString(dataReader["Address"]);
user.Age = Convert.ToInt32(dataReader["Age"]);
user.Department = Convert.ToString(dataReader["Department"]);
user.FirstName = Convert.ToString(dataReader["FirstName"]);
user.LastName = Convert.ToString(dataReader["LastName"]);
user.LastSSN = Convert.ToString(dataReader["LastSSN"]);
user.MaritalStatus = Convert.ToString(dataReader["MaritalStatus"]);
user.Salary = Convert.ToString(dataReader["Salary"]);
users.Add(user);
}
}
}
}
return users;
} /// <summary>
///
/// </summary>
/// <param name="numberOfRows"></param>
/// <param name="pageIndex"></param>
/// <param name="sortColumnName"></param>
/// <param name="sortOrderBy"></param>
/// <param name="totalRecords"></param>
/// <returns></returns>
private List<Employee> GetUsers(string numberOfRows, string pageIndex, string sortColumnName, string sortOrderBy, out int totalRecords)
{
List<Employee> users = new List<Employee>();
string connectionString = @"Data Source=GEOVINDU; Initial Catalog=AdventureWorks2012; User ID=sa; Password=geovindu";
using (SqlConnection connection = new SqlConnection(connectionString))
{
using (SqlCommand command = new SqlCommand())
{
command.Connection = connection;
command.CommandText = "SelectjqGridUsers";
command.CommandType = CommandType.StoredProcedure; SqlParameter paramPageIndex = new SqlParameter("@PageIndex", SqlDbType.Int);
paramPageIndex.Value = Convert.ToInt32(pageIndex);
command.Parameters.Add(paramPageIndex); SqlParameter paramColumnName = new SqlParameter("@SortColumnName", SqlDbType.VarChar, 50);
paramColumnName.Value = sortColumnName;
command.Parameters.Add(paramColumnName); SqlParameter paramSortorderBy = new SqlParameter("@SortOrderBy", SqlDbType.VarChar, 4);
paramSortorderBy.Value = sortOrderBy;
command.Parameters.Add(paramSortorderBy); SqlParameter paramNumberOfRows = new SqlParameter("@NumberOfRows", SqlDbType.Int);
paramNumberOfRows.Value = Convert.ToInt32(numberOfRows);
command.Parameters.Add(paramNumberOfRows); SqlParameter paramTotalRecords = new SqlParameter("@TotalRecords", SqlDbType.Int);
totalRecords = 0;
paramTotalRecords.Value = totalRecords;
paramTotalRecords.Direction = ParameterDirection.Output;
command.Parameters.Add(paramTotalRecords); connection.Open();
using (SqlDataReader dataReader = command.ExecuteReader())
{
Employee user;
while (dataReader.Read())
{
user = new Employee();
user._id = Convert.ToString(dataReader["_id"]);
user.Address = Convert.ToString(dataReader["UserName"]);
user.Age = Convert.ToInt32(dataReader["Age"]);
user.Department = Convert.ToString(dataReader["Department"]);
user.FirstName = Convert.ToString(dataReader["FirstName"]);
user.LastName = Convert.ToString(dataReader["LastName"]);
user.LastSSN = Convert.ToString(dataReader["LastSSN"]);
user.MaritalStatus = Convert.ToString(dataReader["MaritalStatus"]);
user.Salary = Convert.ToString(dataReader["Salary"]);
users.Add(user);
}
}
totalRecords = (int)paramTotalRecords.Value;
} return users;
} } /// <summary>
/// 添加,修改
/// </summary>
/// <param name="forms"></param>
/// <param name="collectionEmployee"></param>
/// <param name="strResponse"></param>
private void AddEdit(NameValueCollection forms, MongoCollection collectionEmployee,out string strResponse)
{
string strOperation = forms.Get("oper");
string strEmpId = string.Empty;
if (strOperation == "add") //添加
{
var result = 40;// collectionEmployee.AsQueryable<Employee>().Select(c => c._id).Max();
strEmpId = (Convert.ToInt32(result) + 1).ToString();
}
else if (strOperation == "edit") //编辑
{
strEmpId = forms.Get("EmpId").ToString(); } string strFirstName = forms.Get("FirstName").ToString();
string strLastName = forms.Get("LastName").ToString();
string strLastSSN = forms.Get("LastSSN").ToString();
string strDepartment = forms.Get("Department").ToString();
string strAge = forms.Get("Age").ToString();
string strSalary = forms.Get("Salary").ToString();
string strAddress = forms.Get("Address").ToString();
string strMaritalStatus = forms.Get("MaritalStatus").ToString();
Employee objEmp = new Employee();
objEmp._id = strEmpId;
objEmp.FirstName = strFirstName;
objEmp.LastName = strLastName;
objEmp.LastSSN = strLastSSN;
objEmp.Department = strDepartment;
objEmp.Age = Convert.ToInt32(strAge);
objEmp.Address = strAddress;
objEmp.MaritalStatus = strMaritalStatus;
objEmp.Salary = strSalary; //collectionEmployee.Save(objEmp);
strResponse = "Employee record successfully updated";
}
}
JqGrid: Add,Edit,Del in asp.net的更多相关文章
- ASP.NET MVC开发,编辑页面和添加页面基本相同,我们控制器 Add Edit是共用同一个View吗?
http://q.cnblogs.com/q/51693/ 这种的话,一般公用就好了.,如下的写法: [HttpGet] public ActionResult UserManage(int user ...
- ASTreeView Demo:Add, Edit & Delete nodes
http://www.jinweijie.com/ http://www.astreeview.com/astreeviewdemo/astreeviewdemo1.aspx 選擇節點: <sc ...
- Eclipse User Library Add/Edit/Remove
1:前文 近来开发项目采用的技术是AngularJS+Bootstrap+Spring Boot+SpringMvc+JPA 的方式,创建的项目是 Java Project,对应的JAR文件需要添加到 ...
- ASP.NET中使用JqGrid完整实现
文章提纲 介绍 & 使用场景 JqGrid的一些说明 JqGrid和ASP.NET整合详细步骤 前置准备 框架搭建 数据填充 数据增/删/改 其他 介绍&使用场景 JqGrid不是一个 ...
- Asp.Net MVC中使用ACE模板之Jqgrid
第一次看到ACE模板,有种感动,有种相见恨晚的感觉,于是迅速来研究.它本身是基于bootstrap和jqueryui,但更nice,整合之后为后台开发节省了大量时间. 发现虽然不是完美,整体效果还是不 ...
- ACE模板之Jqgrid
Asp.Net MVC中使用ACE模板之Jqgrid 第一次看到ACE模板,有种感动,有种相见恨晚的感觉,于是迅速来研究.它本身是基于bootstrap和jqueryui,但更nice,整合之后为 ...
- easyui-tabs 页签绑定click事件,动态加载jqgrid
.前台代码 <%-- builed by manage.aspx.cmt [ver:] at // :: --%> <%@ Page Language="C#" ...
- WinForm BaseClass类常用通用方法
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.D ...
- Maven+Spring+Hibernate+Shiro+Mysql简单的demo框架(一)
相关的maven的 pom.xml <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="ht ...
随机推荐
- DataBrewery Cubes 连接Kylin
问题背景 Kylin作为一个极其优秀的MOLAP,提供了完整的Cube创建.更新流程.同时提供了Sql查询.功能上看没有问题,但是在提供查询服务的时候还是有些不友好. sql查询需要常常需要关联Hiv ...
- ASP.NET Core 请求/查询/响应参数格式转换(下划线命名)
业务场景: 在 ASP.NET Core 项目中,所有的代码都是骆驼命名,比如userName, UserName,但对于 WebApi 项目来说,因为业务需要,一些请求.查询和响应参数的格式需要转换 ...
- Unity全面的面试题(包含答案)
一:什么是协同程序? 在主线程运行的同时开启另一段逻辑处理,来协助当前程序的执行,协程很像多线程,但是不是多线程,Unity的协程实在每帧结束之后去检测yield的条件是否满足. 二:Unity3D中 ...
- FTPClient 中 FTPClient.changeWorkingDirectory(filePath) 代码一直返回 false
FTP文件下载需要的jar包: commons-net-2.0.jar 有时可能还需要:jakarta-oro.jar 参考:FTPClient参考文档 这里记录下我碰到的问题: 刚开始我的账号和密 ...
- Python - 集成开发环境Pycharm的使用方法和技巧
PyCharm HomePage:PyCharm 我的Pycharm,我做主 Getting Started with PyCharm Pycharm使用技巧 Documentation & ...
- vertical-align css属性
vertical-align 属性设置元素的垂直对齐方式. vertical-align 的属性值: baseline:默认.元素放置在父元素的基线上. sub:垂直对齐文本的下标. super:垂直 ...
- postgresql-分页重复数据探索
# postgresql-分页重复数据探索 ## 问题背景 许多开发和测试人员都可能遇到过列表的数据翻下一页的时候显示了上一页的数据,也就是翻页会有重复的数据. ### 如何处理? 这个问题出现的原因 ...
- Keras 资源
Keras中文文档 github Keras example 官方博客 A ten-minute introduction to sequence-to-sequence learning in Ke ...
- [视频]K8飞刀 exploit管理功能 演示教程
[视频]K8飞刀 exp管理功能 演示教程 链接: https://pan.baidu.com/s/1rYb3rh4od3j07TZAAq_smw 提取码: kksa
- 关于requests的session方法保持cookie的问题。
最近在做爬虫的时候遇到了一个问题,在用requests的session方法保持cookie的时候发现requests不能保持手动构建的cookie.起初以为requests只能自动保持由服务器返回的s ...