问题C# asp.net gridview 查询后分页的问题 单击第二页时数据重新绑定了。 5
查询:stringsqlstr="select因字数限制省略";SqlCommandcmd=newSqlCommand(sqlstr,conn);SqlDataAdapt...
查询:
string sqlstr = "select 因字数限制省略";
SqlCommand cmd = new SqlCommand(sqlstr, conn);
SqlDataAdapter sda = new SqlDataAdapter();
sda.SelectCommand = cmd;
DataSet ds = new DataSet();
DataTable dtSelect = new DataTable();
conn.Open();
sda.Fill(ds,"workjl");
GridView1.DataSource = ds.Tables[0];//引用强数据集中的DataTable;
GridView1.DataKeyNames = new string[] { "xh" };
GridView1.DataBind();
conn.Close();
翻页事件
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
bind();
}
public void bind()
{
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString3"].ConnectionString);
//string sqlstr = "select * from workjl";
string sqlstr = "select 因字数限制省略";
SqlDataAdapter myda = new SqlDataAdapter(sqlstr, conn);
DataSet myds = new DataSet();
conn.Open();
myda.Fill(myds, "workjl");
GridView1.DataSource = myds;
GridView1.DataKeyNames = new string[] { "xh" };
GridView1.DataBind();
conn.Close();
} 展开
string sqlstr = "select 因字数限制省略";
SqlCommand cmd = new SqlCommand(sqlstr, conn);
SqlDataAdapter sda = new SqlDataAdapter();
sda.SelectCommand = cmd;
DataSet ds = new DataSet();
DataTable dtSelect = new DataTable();
conn.Open();
sda.Fill(ds,"workjl");
GridView1.DataSource = ds.Tables[0];//引用强数据集中的DataTable;
GridView1.DataKeyNames = new string[] { "xh" };
GridView1.DataBind();
conn.Close();
翻页事件
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
bind();
}
public void bind()
{
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString3"].ConnectionString);
//string sqlstr = "select * from workjl";
string sqlstr = "select 因字数限制省略";
SqlDataAdapter myda = new SqlDataAdapter(sqlstr, conn);
DataSet myds = new DataSet();
conn.Open();
myda.Fill(myds, "workjl");
GridView1.DataSource = myds;
GridView1.DataKeyNames = new string[] { "xh" };
GridView1.DataBind();
conn.Close();
} 展开
2013-09-28
展开全部
加载时绑定要加上 if(!ispostback)判断。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询