下拉列表选择事件在GridView中出现问题 [英] Problem in gridview at dropdown list select event

查看:76
本文介绍了下拉列表选择事件在GridView中出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下是我编写的代码:-

Following is the code that I have written:-

protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
  {
      SqlCommand com1 = new SqlCommand("quot;select sno,adv,city from adv1 where categry=@b",con);
      com1.Parameters.AddWithValue("@b", DropDownList1.Text);
      con.Open();
      GridView1.DataSource = com1.ExecuteReader();
      con.Close();
      GridView1.DataBind();
}



在网格视图下,我有以下内容:



And under grid view I have the following:

protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        GridView1.PageIndex = e.NewPageIndex;
        GridView1.AllowPaging = true;
    }


它给出以下错误:数据源不支持服务器端数据分页."
有人可以提供帮助吗?


It gives this error: "The data source does not support server-side data paging."
anyone can help?

推荐答案

要进行分页,您需要使用DataAdapter. ExecuteReader 仅是转发的连接数据形式.因此,您将无法进行服务器端分页.

更新:
类似的讨论:链接1 [ ^ ],链接2 [ ^ ]

试试类似的东西:
In order to have paging you need to use DataAdapter. ExecuteReader is forward only, connected data form. Thus you won''t be able to have server side pagin.

UPDATE:
Similar discussions: Link 1[^], Link 2[^]

Try something like:
DataTable dt = new DataTable();       
SqlDataAdapter ad = new SqlDataAdapter(cmd);
ad.Fill(dt);
GridView1.DataSource = dt;
GridView1.DataBind();


将错误消息(引号之间的部分)粘贴到您最喜欢的Internet搜索引擎的搜索框中,然后按回车键.

您将在所获得的点击中找到几乎所有可能的解决方案.

仔细阅读,直到找到适合您的情况为止.
Take your error message (the part between the quotes) and paste it into the search box of your favourite internet search engine then hit return.

You will find almost all the possible solutions in the hits that you get.

Have a read until you find one that works for your situation.


您可以尝试以下方法:


You can try as bellow:


protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
  {
      SqlCommand com1 = new SqlCommand("select sno,adv,city from adv1 where categry=@b",con);
      com1.Parameters.AddWithValue("@b", DropDownList1.Text);
      con.Open();

      SqlDataAdapter da=new SqlDataAdapter(com1); 
      DataSet ds=new DataSet();
      da.Fill(ds);
      GridView1.DataSource = ds.Tables[0];
      GridView1.DataBind();
      con.Close();
}

protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        //GridView1.PageIndex = e.NewPageIndex; //with or without
        GridView1.AllowPaging = true;
    }



谢谢,
马蒙



Thanks,
Mamun


这篇关于下拉列表选择事件在GridView中出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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