日期:2014-05-18  浏览次数:20805 次

非常急的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() + "'";
  }