用 SqlDataSource 控件绑定 DataView控件 我已经会了,但是我想用手动编写代码绑定数据库,显示数据库中的数据,并且可以翻页。我连接数据库和查询的代码是:SqlConnection myConnection = new SqlConnection("server=127.0.0.1;database=test;uid=sa;pwd=sa");SqlCommand myCommand = new SqlCommand("select * from liuyan", myConnection);我要显示出 id  biaoti  neirong  这三个字段,把它们显示在 DataView 空间中,并且每页5条,可以翻页的。有时有总提示不支持回调什么的,就这样报错,请各位专家为我指点指点!谢谢了!

解决方案 »

  1.   

    查询结果集放到一个DATATABLE里,绑到GRIDVIEW
    分页可以写好分页的SQL绑GRIDVIEW
    也可以全部结果集绑GRIDVIEW用GRIDVIEW分页
      

  2.   

    private void dgBind()
        {
            SqlConnection conn = new SqlConnection("server=127.0.0.1;database=test;uid=sa;pwd=sa");
            SqlDataAdapter sda = new SqlDataAdapter();
            sda.SelectCommand = new SqlCommand("select * from liuyan where postID='1'", conn);
            DataSet ds = new DataSet();
            sda.Fill(ds, "arc");
            this.dgArticles.DataKeyField = "id";
            this.dgArticles.DataSource = ds.Tables["arc"];
            this.dgArticles.DataBind();
            conn.Close();
     
        }
    在page_load事件里调用这个就可以了
      

  3.   

    GridView1.EnableSortingAndPagingCallbacks<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" SkinID="GridViewSkin" Width="100%" AllowPaging="True" AllowSorting="True" OnRowCreated="GridView1_RowCreated" OnPageIndexChanging="GridView1_PageIndexChanging" >
                                <Columns>
                                    <asp:BoundField DataField="id" HeaderText="编号" SortExpression="ProductId" />
                                    <asp:BoundField DataField="biaoti" HeaderText="类别" SortExpression="ProductId" />
                                    <asp:BoundField DataField="neirong" HeaderText="名称" SortExpression="ProductId" />
                                </Columns>
                                <PagerSettings Mode="NumericFirstLast" />
                            </asp:GridView>
            GridView1.DataSource = ds.Tables[0].DefaultView;
            GridView1.DataBind();
      

  4.   

    解决EnableSortingAndPagingCallbacks失效的办法 1     protected void Page_Load(object sender, EventArgs e)
     2     {
     3             xx();
     4         
     5     }
     6 
     7     private void xx()
     8     {
     9         SqlConnection conn = new SqlConnection();
    10         conn.ConnectionString = "server=wumeibo\\wmb;database=northwind;uid=sa;pwd=sa;";
    11    
    12         SqlDataSource source = new SqlDataSource();
    13         source.ConnectionString = "server=wumeibo\\wmb;database=northwind;uid=sa;pwd=sa;";
    14         source.SelectCommand = "select * from products";
    15 
    16         this.Gridviewex1.DataSource = source;
    17         this.Gridviewex1.DataBind();
    18     }
      

  5.   

    我还真会了。挺简单的。原来C#好像有些地方比ASP还简单的多。各位辛苦了,接分!