GridView控件和寻呼asp.net [英] gridview control and paging asp.net

查看:130
本文介绍了GridView控件和寻呼asp.net的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有被在后端code填充一个gridview。我想现在实现分页,但是当我想我的路,我得到什么。
这里是我的一块code的:

I have a gridview which gets populated in the backend code. I am trying to implement paging now, but when I am trying my way, I am getting nothing. Here is my piece of code:

public void generateTable()
{
    conn.ConnectionString = connString;
    SqlCommand comm = new SqlCommand("ViewBusinessInfo", conn);
    comm.CommandType = CommandType.StoredProcedure;
    comm.CommandTimeout = 2;
    try
    {
        conn.Open();
        SqlDataReader rdr = comm.ExecuteReader();

        if (rdr.HasRows)
        {
            gvAssociation.DataSource = rdr;
            gvAssociation.DataBind();
            gvAssociation.AllowPaging = true;
            gvAssociation.PageSize = 10;
            rdr.Close();
        }
        else
        {
            lblResult.Text = "No businesses found.";
            lblResult.Visible = true;
        }

    }
    catch
    {
    }
    finally
    {
        conn.Close();
    }
}

任何人都可以建议我在做什么错了,我不能让在GridView分页?
THX在前进,Laziale

Can anyone advice what am I doing wrong and I can't get the paging in the gridview? Thx in advance, Laziale

推荐答案

您不能使用分页使用DataReader。应填写您的数据到数据集或数据表使用DataAdapter。事情是这样的:

You cannot use paging with a DataReader. You should fill your data into a Dataset or a Datatable using a DataAdapter. Something like this:

 SqlCommand myCommand = new SqlCommand("ViewBusinessInfo", conn);
 SqlDataAdapter myAdapter = new SqlDataAdapter(myCommand))
 DataTable dt = new DataTable();
 myAdapter.Fill(dt);
 ...

这篇关于GridView控件和寻呼asp.net的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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