Gets the data for the DataGrid selected row, displayed in the Windows window

Source: Internet
Author: User

(On the basis of the last essay code)

1.datagrid Code:

<div style= "width:100%;height:100%;" >
<table class= "Easyui-datagrid" id= "Datagriduser" style= "width:100%; height:95%; "data-options=" Singleselect:true,url: ' @Url. Action ("GetList") ', Method: ' Get ',Toolbar:toolbar "Pagination= "true" Sortname= "Id" sortorder= "ASC" >
<thead>
<tr>
<th style= "width:10%" data-options= "field: ' Id '"Sortable= "true" > Numbering </th>
<th style= "width:15%" data-options= "field: ' Name '" sortable= "true" > Login </th>
<th style= "width:15%" data-options= "field: ' Realname '" sortable= "true" > Name </th>
<th style= "width:15%" data-options= "field: ' Sex '" sortable= "true" > Gender </th>
<th style= "width:15%" data-options= "field: ' Email '" > email </th>
<th style= "width:15%" data-options= "field: ' Phone '" > Phone </th>
<th style= "width:15%" data-options= "field: ' Address '" > Addresses </th>
</tr>
</thead>
</table>
</div>

2.JS Code

<script type= "Text/javascript" >
var toolbar = [{
Text: ' Delete user ',
Iconcls: ' Icon-clear ',
Handler:function () {
var row = $ ("#datagridUser"). DataGrid ("getselected");
if (row! = null) {
var userId = row. Id;
Perform a delete operation
if (Confirm ("Confirm delete?") "))
{
$.ajax ({
Type: "POST",
URL: "/usermanager/deleteuser",
Data: "id=" + userId,
Success:function (Result) {
if (result = = "true") {
$ ("#datagridUser"). DataGrid ("Reload");
}
}
});
}
}
else {
Alert ("Please select the item you want to delete!") ");
}
}
}, {
Text: ' View Details ',
Iconcls: ' Icon-search ',
Handler:function () {
var row = $ ("#datagridUser"). DataGrid ("getselected");
if (row! = null) {
Binding form data
var userId = row. Id;
Perform a query operation
$.ajax ({
Type: "Get",
URL: "/usermanager/getuser",
Data: "id=" + userId,
Success:function (Jsonuserinfo) {
var json = Json.parse (jsonuserinfo);
$ ("#textInfoName"). Val (JSON. Name);
$ ("#textInfoRealName"). Val (JSON. Realname);
$ ("#textInfoSex"). Val (JSON. SEX);
$ ("#textInfoEmail"). Val (JSON. Email);
$ ("#textInfoPhone"). Val (JSON. Phone);
$ ("#textInfoAddress"). Val (JSON. Address);

Open window, center display
$ (' #windowUserInfo '). Window ({
Top: ($ (window). Height ()-300) * 0.5,
Left: ($ (window). Width ()-500) * 0.5,
}). window (' open ');
}
});
}
else {
Alert ("Please select User!") ");
}
}
}];
</script>

Note: var row = $ ("#datagridUser"). The DataGrid ("getselected") gets the selected row; var userId = row. ID gets the ID of the row data; URL: "/usermanager/getuser" Ajax invokes action to get data; My action returns a JSON string;$ ("#textInfoName"). val (JSON. Name) to bind the display data .

3.control

[HttpPost]
Public ActionResult deleteuser (int id)
{
var user = Userservice.get (x = x.id = = Id); Gets the user to delete
if (userservice.delete (user))
{
Return Content ("true");
}
Else
{
Return Content ("false");
}
}

[HttpGet]
public string GetUser (int id)
{
var user = Userservice.get (x = x.id = = Id); Gets the user to delete
var json = jsonconvert.serializeobject (user);
return JSON;
}

Note: The code is only part, the memo is convenient to view later

Gets the data for the DataGrid selected row, displayed in the Windows window

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.