datagrid 分页问题 在发(在线)
这个是我写的分页代码,点下一页的时候它不显示下一页信息,请大哥们看看
着急啊~~~
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
public partial class admin_cus_manage_shiyan : System.Web.UI.Page
{
protected SqlConnection con;
protected SqlDataAdapter sda;
protected DataSet ds;
protected string strsql;
protected void Page_Load(object sender, EventArgs e)
{
strsql = "select business_id,[User_name],Business_name,Business_company,Business_issuance from business where Business_authentication= 'n ' ";
BindGrid(strsql);
}
protected void BindGrid(string sql)
{
con = new SqlConnection(ConfigurationSettings.AppSettings[ "Str_sql "]);
sda = new SqlDataAdapter(sql, con);
ds = new DataSet();
sda.Fill(ds);
DataGrid1.DataSource = ds.Tables[0].DefaultView;
DataGrid1.DataBind();
}
protected void DataGrid1_PageIndexChanged(object source, DataGridPageChangedEventArgs e)
{
DataGrid1.CurrentPageIndex = e.NewPageIndex;
BindGrid(strsql);
}
protected void LinkButton2_Click(object sender, EventArgs e)
{
if (DataGrid1.CurrentPageIndex < (DataGrid1.PageCount - 1))
{
DataGrid1.CurrentPageIndex += 1;
}
BindGrid(strsql);
}
protected void LinkButton1_Click(object sender, EventArgs e)
{
if (DataGrid1.CurrentPageIndex > 0)
{
DataGrid1.CurrentPageIndex -= 1;
}
BindGrid(strsql);
}
}
[解决办法]
你写的Sql语句能执行通吗?
protected void Page_Load(object sender, EventArgs e)
{
if(!Page.IsPostBack)
{
BindGrid();
}
}
protected void BindGrid()
{
strsql = "select business_id,[User_name],Business_name,Business_company,Business_issuance from business where Business_authentication= 'n ' ";
con = new SqlConnection(ConfigurationSettings.AppSettings[ "Str_sql "]);
SqlDataAdapter sda = new SqlDataAdapter(sql, con);
DataSet ds = new DataSet();
sda.Fill(ds);
DataGrid1.DataSource = ds.Tables[0].DefaultView;
DataGrid1.DataBind();
}
执行看看
[解决办法]
还有
SqlConnection con = new SqlConnection(ConfigurationSettings.AppSettings[ "Str_sql "]);
[解决办法]
public static readonly string connectionStr = "Data Source=HUANGXIN;Initial Catalog=account;uid=sa;pwd=sa ";
string sql = "select * from account ";
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindData(sql);
}
}
private void BindData(string sql)
{
SqlConnection con = new SqlConnection(connectionStr);
SqlDataAdapter sda = new SqlDataAdapter(sql, con);
DataSet set = new DataSet();
sda.Fill(set);
this.DataGrid1.DataSource = set;
this.DataGrid1.DataBind();
}
protected void DataGrid1_PageIndexChanged(object source, DataGridPageChangedEventArgs e)
{
this.DataGrid1.CurrentPageIndex = e.NewPageIndex;
BindData(sql);
}
[解决办法]
con.open();掉了这一句,加上就行了!
[解决办法]
少了这个
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
.................
}
}
[解决办法]
open()了要 关
con.close()放到SqlDataAdapter sda = new SqlDataAdapter(sql, con);
后面
[解决办法]
楼上的解释全不对!
楼主的设计就是错的
protected string strsql; ★这里是空值!!!!
protected void Page_Load(object sender, EventArgs e)
{
strsql = "select business_id, [User_name],Business_name,Business_company,Business_issuance from business where Business_authentication= 'n ' "; ★而这里给了临时的附值!!
BindGrid(strsql);
}
当PAGELOAD的时候绑定正常
但在是事件处理中, 新的SQL操作中,命令是空的。
[解决办法]
现在我分页代码都是自己写的了...
datagrid控件我用着难受...