我在grid的Toolbar里面有一个TwinTriggerBox,用来搜索数据使用
点击事件如下:
protected void ttbxMyBox2_Trigger2Click(object sender, EventArgs e)
{
searchKey = tb_searchKey.Text.ToString().Trim();
BindGrid();
//Alert.Show(searchKey);
}
protected void ttbxMyBox2_Trigger1Click(object sender, EventArgs e)
{
tb_searchKey.Text = "";
searchKey = "";
Grid1.PageIndex = 0;
BindGrid();
}
程序的获取数据分页程序如下:
private void BindGrid()
{
// 1.设置总项数
Grid1.RecordCount = GetTotalCount();
// 2.获取当前分页数据
DataSet table = GetPagedDataTable(Grid1.PageIndex, Grid1.PageSize);
// 3.绑定到Grid
Grid1.DataSource = table;
Grid1.DataBind();
}
private int GetTotalCount()
{
sqlstring = "select count(id) from KcCustom";
int totalcount = Convert.ToInt32(SqlHelper.ExecuteScalar(SqlHelper.connectionString, CommandType.Text, sqlstring));
return totalcount;
}
private DataSet GetPagedDataTable(int pageIndex, int pageSize)
{
DataSet source;
int pageindex = pageIndex;
int pagesize = pageSize;
if (pagesize <= 0) { pagesize = 30; }
if (pageindex < 0) { pageindex = 0; }
if (!string.IsNullOrEmpty(searchKey))
{
SqlParameter[] cs4 = new SqlParameter[1];
cs4[0] = new SqlParameter("@searchKey", searchKey);
sqlstring = "select top " + pagesize + " id,customId,customName,customMobile,customAdd,customBz,customType,jizhangMax,tixingMoney,customLock from KcCustom where customName=@searchKey";
//if (pageindex > 0)
//{
// sqlstring = sqlstring + " and id>(select max (id) from (select top ((" + pageindex + ")*" + pagesize + ") id from KcCustom order by id) as T) order by id";
//}
source = SqlHelper.ExecuteDataset(SqlHelper.connectionString, CommandType.Text, sqlstring, cs4);
}
else
{
sqlstring = "select top " + pagesize + " id,customId,customName,customMobile,customAdd,customBz,customType,jizhangMax,tixingMoney,customLock from KcCustom where 1=1";
if (pageindex > 0)
{
sqlstring = sqlstring + " and id>(select max (id) from (select top ((" + pageindex + ")*" + pagesize + ") id from KcCustom order by id) as T) order by id";
}
source = SqlHelper.ExecuteDataset(SqlHelper.connectionString, CommandType.Text, sqlstring);
}
return source;
}
protected void Grid1_PageIndexChange(object sender, ExtAspNet.GridPageEventArgs e)
{
Grid1.PageIndex = e.NewPageIndex;
BindGrid();
}
点击搜索后会出现如下错误
消息: 'undefined' 为空或不是对象
行: 1
字符: 73184
代码: 0
URI: http://localhost/WebResource.axd?d=7OVFSIZ3yBcL8zot75-qFGOzjP-pQ9OwmI30n5dWnCwNudpmO2N8PkN3EMab7nf_us8cDRysBjGpEkCcAkwQT3LmzHHDt3zQRo2QFd1zT2AZ8Jz4wWQYtCoV2xVuxECq1UxqWayUHRcqlxtG0y_LHQ2&t=634719409400000000
请问是什么原因呀,弄了很久都没弄好
|