1个回答
展开全部
-----------前台代码-------------
<script type="text/javascript">
var manager, g;
function f_initGrid() {
g = manager = $("#toolgrid").ligerGrid({
columns: [
{ display: '名称', name: 'name', width: 300, isSort: false, editor: { type: 'text'} },
{ display: '日期', name: 'createdate', width: 100, type: 'text', isSort: false, editor: { type:
'text'} }
],
isScroll: false, usePager: true, checkbox: false,
width: '600',
pageSize: 10,
rownumbers: true
});
}
function f_reload() {
var data = {};
$.ajax({
type: 'post',
url: 'ajax.aspx?no-cache=' + Math.random(),
data: 'Option=getlist',
success: function (msg) {
data = eval('(' + msg + ')');
g.set({ data: data });
g.loadData();
}
});
}
$(function () {
f_initGrid();
f_reload();
});
</script>
<div id="toolgrid" style="margin: 0px 10px 5px;"></div>
-----------后台代码ajax.aspx.cs-------------
private string strmsg = "";
protected void Page_Load(object sender, EventArgs e)
{
Response.CacheControl = "no-cache";
try
{
if (Request["Option"] != null)
{
switch (Request["Option"].ToString())
{
case "getlist": strmsg = GetList(); break;
}
}
}
catch
{
strmsg = "";
}
Response.Clear();
Response.Write(strmsg);
Response.End();
}
protected string GetList()
{
string str = "";
List<Test> list = new List<Test>();
string str2 = "[]";
try
{
DataTable dt = GetTable();//获取数据
for (int i = 0; i < dt.Rows.Count; i++)
{
Test model = new Test();
model.id = Convert.ToInt32(dt.Rows[i]["id"]);
model.name = Convert.ToString(dt.Rows[i]["name"]);
model.createdate = Convert.ToDateTime(dt.Rows[i]["createdate"]).ToString("yyyy-MM-dd");
list.Add(model);
}
if (list.Count > 0)
{
str2 = Common.JsonHelper.Serialize(list);
}
}
catch
{ }
str = "{ Rows: " + str2 + ", Total: " + list.Count + " }";
return str;
}
<script type="text/javascript">
var manager, g;
function f_initGrid() {
g = manager = $("#toolgrid").ligerGrid({
columns: [
{ display: '名称', name: 'name', width: 300, isSort: false, editor: { type: 'text'} },
{ display: '日期', name: 'createdate', width: 100, type: 'text', isSort: false, editor: { type:
'text'} }
],
isScroll: false, usePager: true, checkbox: false,
width: '600',
pageSize: 10,
rownumbers: true
});
}
function f_reload() {
var data = {};
$.ajax({
type: 'post',
url: 'ajax.aspx?no-cache=' + Math.random(),
data: 'Option=getlist',
success: function (msg) {
data = eval('(' + msg + ')');
g.set({ data: data });
g.loadData();
}
});
}
$(function () {
f_initGrid();
f_reload();
});
</script>
<div id="toolgrid" style="margin: 0px 10px 5px;"></div>
-----------后台代码ajax.aspx.cs-------------
private string strmsg = "";
protected void Page_Load(object sender, EventArgs e)
{
Response.CacheControl = "no-cache";
try
{
if (Request["Option"] != null)
{
switch (Request["Option"].ToString())
{
case "getlist": strmsg = GetList(); break;
}
}
}
catch
{
strmsg = "";
}
Response.Clear();
Response.Write(strmsg);
Response.End();
}
protected string GetList()
{
string str = "";
List<Test> list = new List<Test>();
string str2 = "[]";
try
{
DataTable dt = GetTable();//获取数据
for (int i = 0; i < dt.Rows.Count; i++)
{
Test model = new Test();
model.id = Convert.ToInt32(dt.Rows[i]["id"]);
model.name = Convert.ToString(dt.Rows[i]["name"]);
model.createdate = Convert.ToDateTime(dt.Rows[i]["createdate"]).ToString("yyyy-MM-dd");
list.Add(model);
}
if (list.Count > 0)
{
str2 = Common.JsonHelper.Serialize(list);
}
}
catch
{ }
str = "{ Rows: " + str2 + ", Total: " + list.Count + " }";
return str;
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询