如何在自定义代码中启用分页? [英] how do enable paging in a custom code?

查看:76
本文介绍了如何在自定义代码中启用分页?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以帮我纠正这段代码!

Can someone help me correct this code!

public DataView binddata()
      {

          string ConnectionString = ConfigurationManager.ConnectionStrings["lawrece"].ConnectionString;
          SqlConnection con = new SqlConnection(ConnectionString);

          String StrQuery = "select * from TableName";
          SqlDataAdapter adp = new SqlDataAdapter(StrQuery, con);
          DataSet ds = new DataSet();
          adp.Fill(ds);
          if (ViewState["sortExpr"] != null)
          {
              DataView dv = new DataView(ds.Tables[0]);
              dv.Sort = (string)ViewState["sortExpr"];
          }

          else
          {
              DataView dv = ds.Tables[0].DefaultView;
              return dv;
          }


      }
 protected void GridView2_PageIndexChanging(Object sender, GridViewPageEventArgs e)
      {
          GridView2.PageIndex = e.NewPageIndex;
          GridView2.DataSource = bindgrid();
          GridView2.DataBind();
      }



但是当我构建以上内容时我会收到这些错误


But when i build the above i get these errors

'lawrence.open.Default.bindgrid()': not all code paths return a value'



我错过了该代码的一行吗?目的是在我的网格视图上启用分页,以便在点击页码时页面将打开。



如果还有其他人这样做,我将不胜感激。 ...谢谢


Am i missing a line on that code? The aim is to enable paging on my grid view so that when the page number is clicked the page will open.

If there is another to do that i will appreciate....thanks

推荐答案





看到我对你的代码的评论



Hi,

see my comments on your code

public DataView binddata()
        {
 
            string ConnectionString = ConfigurationManager.ConnectionStrings["lawrece"].ConnectionString;
            SqlConnection con = new SqlConnection(ConnectionString);
 
            String StrQuery = "select * from TableName";
            SqlDataAdapter adp = new SqlDataAdapter(StrQuery, con);
            DataSet ds = new DataSet();
            adp.Fill(ds);
            DataView dv = new DataView();    // create dataview object here
            if (ViewState["sortExpr"] != null)
            {
                dv = new DataView(ds.Tables[0]);
                dv.Sort = (string)ViewState["sortExpr"];
            }
 
            else
            {
                dv = ds.Tables[0].DefaultView;
                
            }
 
             return dv;   //return outside of if,else
        }





希望有帮助



Hope it helps


这篇关于如何在自定义代码中启用分页?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆