Easyui之datagrid后台查询
怎么用datagrid查询
在页面放一个
<asp:button id=btn1 runat=server οnclick=“doSearch” Text=“检索” />
代码里:
void Page_Load()
{
if(!IsPostBack)
{
//刚进来时没有检索,显示全部
sql = “select * from table”;
//datagrid绑定代码
}
}
void doSearch(object sender,EventArgs e)
{
sql = “Select * from Table where 1=1”;
if(TextBox1.text != “”)
{
sql += " and 姓名=’"+TextBox1.text+"’";
}
if(TextBox2.text != “”)
{
sql += " and 密码=’"+TextBox2.text+"’";
}
//datagrid绑定代码
}
案例(代码块)
book.js
$(function(){
var ctx=$("#ctx").val();
$('#dg').datagrid({
url:ctx+'/book.action?methdName=datagrid',
pagination:true,
toolbar:true,
toolbar:'#tb',
columns:[[
{field:'id',title:'id',width:100},
{field:'name',title:'书籍名字',width:100},
{field:'pinyin',title:'拼音',width:100,align:'right'},
{field:'cid',title:'书籍类别',width:100},
{field:'author',title:'作者',width:100},
{field:'price',title:'价格',width:100},
{field:'image',title:'图片',width:100}
]]
});
$("#btn-search").click(function(){
// alert(11);
$('#dg').datagrid('load',{
name: $("#name").val(),
});
});
})