首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

非常急的GridView有关问题.请问!

2012-01-29 
非常急的GridView问题...请教!!!!!我自己设置的datasource..运行之后在GridView中不分页..但是在VS2005编

非常急的GridView问题...请教!!!!!
我自己设置的datasource..运行之后在GridView中不分页..但是在VS2005编辑界面里可以看到分页,..请大家帮忙看一下错在哪?该怎么改?

代码如下:

using System;
using System.Data;
using System.Data.SqlClient;
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;

public partial class baojiamain : System.Web.UI.Page
{
  protected void Page_Load(object sender, EventArgs e)
  {
  TextBox1.Text = "2007-1-1";
  //TextBox1.Text = DateTime.Now.Year.ToString() + ("-") + DateTime.Now.Month.ToString() + ("-") + "1";
  TextBox2.Text = "2099-12-31";
  if (!IsPostBack)
  {
  GridView1.DataSource = mybind();
  GridView1.DataBind();
  GridView2.DataSource = mybind2();
  GridView2.DataBind();
  }
  }
   
  public DataView mybind()
  {

  SqlConnection lj = new SqlConnection(ConfigurationSettings.AppSettings["myconn"]);
  lj.Open();
  string sqla = "select * from sa_quomain order by ccode desc";
  SqlDataAdapter da = new SqlDataAdapter(sqla, lj);
  DataSet ds = new DataSet();
  da.Fill(ds, "congbiao");
  return ds.Tables["congbiao"].DefaultView;
   
  }



  protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
  {
   
  GridView1.PageIndex = e.NewPageIndex;
  GridView1.DataBind();
   

  }
  protected void Button2_Click(object sender, EventArgs e)
  {
  Response.Redirect("cd.aspx");
  }


  protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
  {
  e.Row.Cells[0].Visible = false;
  }

  protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
  {
  if (e.Row.RowType == DataControlRowType.DataRow)
  {
  e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='#33cc00'");

  e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='#DEDFDE'");
  }
  }




  protected void Button8_Click(object sender, EventArgs e)
  {

  SqlConnection lj = new SqlConnection(ConfigurationSettings.AppSettings["myconn"]);
  lj.Open();
  string sql = "select * from sa_quomain";
  if (TextBox6.Text.Trim().Length != 0)
  {
  sql += " where ccode='" + TextBox6.Text.Trim() + "'";
  }
  else
  sql += " where ccode like '%" + "" + "%'";
  if (TextBox7.Text.Trim().Length != 0)
  {
  sql += " and ccuscode='" + TextBox7.Text.Trim() + "'";
  }
  if (TextBox3.Text.Trim().Length != 0)
  {
  sql += " and cpersoncode='" + TextBox3.Text.Trim() + "'";
  }
  if (TextBox4.Text.Trim().Length != 0)
  {
  sql += " and cmaker='" + TextBox4.Text.Trim() + "'";


  }
  if (TextBox1.Text.Trim().Length != 0)
  {
  sql += " and ddate>='" + TextBox1.Text.Trim() + "'";
  }
  if (TextBox2.Text.Trim().Length != 0)
  {
  sql += " and ddate<='" + TextBox2.Text.Trim() + "'";
  }
  sql += " order by ccode desc";


  SqlDataAdapter da = new SqlDataAdapter(sql, lj);
  DataSet ds = new DataSet();
  da.Fill(ds, "zb");
  if (ds.Tables["zb"].Rows.Count != 0)
  {
  GridView1.DataSource = ds;
  GridView1.DataBind();
  }
  else
  {
  Response.Write("<script>alert('没有你要查找的记录!')</script>");

  }
  lj.Close();
  }

  protected void Button3_Click(object sender, EventArgs e)
  {
  Response.Redirect("zjbj1.aspx");
  }
  protected void Button5_Click(object sender, EventArgs e)
  {
  Response.Redirect("zjbj2.aspx");
  }
  protected void Button1_Click(object sender, EventArgs e)
  {
  Response.Redirect("output.aspx");
  }

  public void GridView1_SelectedIndexChanging(object sender, GridViewSelectEventArgs e)
  {
  string mxid = GridView1.Rows[e.NewSelectedIndex].Cells[0].Text;
  Session["mxid"] = mxid;
  SqlConnection lj = new SqlConnection(ConfigurationSettings.AppSettings["myconn"]);
  lj.Open();
  SqlDataAdapter da = new SqlDataAdapter("select * from sa_quodetails where id='" + mxid + "' order by autoid desc ", lj);
  DataSet ds = new DataSet();
  da.Fill(ds, "sa_quodetails");
  GridView2.DataSource = ds;
  GridView2.DataBind();
  lj.Close();

  }




  public DataView mybind2()
  {

  SqlConnection lj = new SqlConnection(ConfigurationSettings.AppSettings["myconn"]);
  lj.Open();
  string sqlabc = "select * from sa_quodetails where id='" + Session["mxid"] + "'";
  SqlDataAdapter da = new SqlDataAdapter(sqlabc, lj);
  DataSet ds = new DataSet();
  da.Fill(ds, "sa_quodetails");
  return ds.Tables["sa_quodetails"].DefaultView;
  lj.Close();

  }

   
   
  protected void GridView2_RowCreated(object sender, GridViewRowEventArgs e)
  {
  e.Row.Cells[0].Visible = false;
  }



  protected void Button4_Click(object sender, EventArgs e)
  {
  SqlConnection abb = new SqlConnection(ConfigurationSettings.AppSettings["myconn"]);
  abb.Open();
  string sqlb = "select * from sa_quodetails where id='" + Session["mxid"] + "'";
   
  string sqld = "delete from sa_quomain where id='" + Session["mxid"] + "'";
  SqlCommand cmd1 = new SqlCommand(sqlb, abb);
  SqlDataReader dr = cmd1.ExecuteReader();
  if (dr.Read())
  {
  Response.Write("<script>alert('因明细存在,系统不允许删除此报价单!')</script>");



  }
  else
  {
  dr.Close();
  SqlCommand cmd = new SqlCommand(sqld, abb);
  cmd.ExecuteNonQuery();
  abb.Close();
  GridView1.DataSource = mybind();
  GridView1.DataBind();
  }

  }


  protected void GridView2_RowDeleting(object sender, GridViewDeleteEventArgs e)
  {

  string wyid = GridView2.Rows[e.RowIndex].Cells[0].Text.ToString();
  SqlConnection lj= new SqlConnection(ConfigurationSettings.AppSettings["myconn"]);
  lj.Open();
  string sqlmm = "delete from sa_quodetails where autoid='" + wyid + "'";
  SqlCommand cmdmm = new SqlCommand(sqlmm, lj);
  cmdmm.ExecuteNonQuery();
  lj.Close();
  GridView2.DataSource = mybind2(); ;
  GridView2.DataBind();
   

  }

  protected void GridView2_RowDataBound(object sender, GridViewRowEventArgs e)
  {

  if (e.Row.RowType == DataControlRowType.DataRow)
  {
  e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='#33cc00'");

  e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor='#DEDFDE'");
  }

  }
}








[解决办法]
检查一下,是否启用了分页
[解决办法]
帮顶
GridView设置是否允许分页,如果不允许,当然不会分页的呀
[解决办法]
1.是否设置了分页
2.检索的数据条数是否大于分页数
[解决办法]
晕```可能是你的设置每页的数据条数大了```
你一共才10条记录``你的PageSize=18
运行后怎么会分页呢```
[解决办法]
呵呵,楼上说的对.呵呵
[解决办法]
既然设置了分页它肯定就会分!
没有分的原因或许只有一个,数据量太少(Ex:允许每页20条记录,现在仅有8条)
[解决办法]
你有多少行数据?分页没有问题.
[解决办法]
如果你在vs里面都看到有分页,可能是因为你的行数不够没有分页!你仔细看看.你查询出来多少条记录!还有你的gridview的foot模板显示出来了吗?
[解决办法]
分頁後需要重新綁定datasource
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e) 

 GridView1.DataSource = l_dt;//必須再次把datasource拿出來綁上,因為分頁後display的數據,實際上只是看到的那一頁,並不是所有的page都有數據
 GridView1.PageIndex = e.NewPageIndex; 
 GridView1.DataBind();


[解决办法]
LZ,你不要把DATAVIEW绑定,直接绑定DATATABLE,看看,我觉得是dataview的问题

热点排行