实现功能:1用datagrid显示数据,跳转页用dropdownlist,此功能已实现,分页显示正常;
          2选中另一个dropdownlist的值做为查询参数查询,现在第一页正常,但是用dropdownlist跳转时,显示的是功能1的 页代码如下:private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
if(!Page.IsPostBack)
{
this.btn_DeleteGroup.Attributes["onclick"] = "return deleteit(this.form)";
this.GroupListDataBind();
}
}private void GroupListDataBind() 
{
string sql="select * from GroupType where IsDeleted=0 order by GroupID desc";
DataTable dt =SqlHelper.ExecuteDataset(BaseConfManager.GetConnectionStr(),CommandType.Text,sql).Tables[0];
if(dt!=null)
{
this.dgdList.DataSource = dt;
this.dgdList.MaxRecord = dt.Rows.Count;
this.dgdList.DataBind();
}
else
{
Response.Write("Error!");
}
}
private void dgdList_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
{
if (e.NewPageIndex >= 0 && e.NewPageIndex <= this.dgdList.PageCount - 1)
{
this.dgdList.CurrentPageIndex = e.NewPageIndex;
}
this.dgdList.SelectedIndex = -1;
this.GroupListDataBind();
this.dgdList.DataBind();
} private void btn_Check_Click(object sender, System.EventArgs e)         //查询按钮
{
string strSql = "";
string strSql1 = ep.ReturnSQLGroup();
if(this.ddl_Field.SelectedItem.Text == "-请选择-" && this.ddl_CreatDate.SelectedItem.Text == "-请选择-")
{
this.GroupListDataBind();
}
else
{
if(this.ddl_Field.SelectedItem.Text != "-请选择-" && this.ddl_CreatDate.SelectedItem.Text != "-请选择-")
{
string gyear=this.ddl_CreatDate.SelectedItem.Value.ToString().Trim();
string gname=this.ddl_Field.SelectedItem.Value.ToString().Trim();
strSql = strSql1 + ep.ReturnSQLGroupgy(gname,gyear);
} this.GroupListOBCDataBind(strSql);
}

} private void GroupListOBCDataBind(string str)  
{
DataSet ds = ep.GetGroupList(str);
if(ds.Tables[0].Rows.Count>0)
{
this.dgdList.DataSource = ds;
this.dgdList.MaxRecord = ds.Tables[0].Rows.Count;
this.dgdList.DataBind();
}
else
{
Response.Write("Error!");
}
}刚接触asp.net,有好多东西不会,请大家帮帮忙,谢谢啊。

解决方案 »

  1.   

    dotnet小白,看一下这段代码private   void   dgdList_PageIndexChanged(object   source,   System.Web.UI.WebControls.DataGridPageChangedEventArgs   e) 

    if   (e.NewPageIndex   > =   0   &&   e.NewPageIndex   <=   this.dgdList.PageCount   -   1) 

    this.dgdList.CurrentPageIndex   =   e.NewPageIndex; 

    this.dgdList.SelectedIndex   =   -1; 
    this.GroupListDataBind(); 
    this.dgdList.DataBind(); 
    } 每次换页都调用GroupListDataBind()方法,这个方法绑定所有数据。
      

  2.   

    没有正常显示,是红色的一句
    private   void   dgdList_PageIndexChanged(object   source,   System.Web.UI.WebControls.DataGridPageChangedEventArgs   e) 

    if   (e.NewPageIndex   > =   0   &&   e.NewPageIndex   <=   this.dgdList.PageCount   -   1) 

    this.dgdList.CurrentPageIndex   =   e.NewPageIndex; 

    this.dgdList.SelectedIndex   =   -1; 
    this.GroupListDataBind(); 
    this.dgdList.DataBind(); 

      

  3.   

    private   void   dgdList_PageIndexChanged(object   source,   System.Web.UI.WebControls.DataGridPageChangedEventArgs   e) 

    if   (e.NewPageIndex   > =   0   &&   e.NewPageIndex   <=   this.dgdList.PageCount   -   1) 

    this.dgdList.CurrentPageIndex   =   e.NewPageIndex; 

    this.dgdList.SelectedIndex   =   -1; 
    this.GroupListDataBind(); 
    this.dgdList.DataBind(); 

    选择页数的时候,应该根据另一个dropdownlist的值做为查询参数查询后绑定的dataGird进行反页
      

  4.   

    public void getData()
    {
       string sql = "";
       string SQLwhere = "(1=1)";
       if(xxx)
       {
         SQLwhere+=xxxx;
       }
       //把你的查询条件全往SQLwhere里面加   填数据方法(sql+SQLwhere);   ----------只是简单举个例子,注意一下注入.
    }getData()就用来取数据..
      

  5.   

    可能是我的表达能力太差了,我现在就想实现:这个datagrid可以分页,跳转哪一页用dropdownlist实现,然后我根据某个条件查询时,这个datagrid只显示符合查询条件的记录并分页。