【问题标题】:Allow sorting=false is not working?允许排序 = false 不起作用?
【发布时间】:2013-08-14 04:01:48
【问题描述】:

在我的网格视图中,我想将新记录插入到网格视图的最后一行。所以我设置Gridview2.Allowsortingfalse。但它不适用于我的网格视图。我的代码在这里

 public void gridview2_selectgroup()
{
    if (Session["selectedgroupes"] != null)
    {
        ArrayList groups = new ArrayList();
        ArrayList student_id_list = new ArrayList();

        groups = (ArrayList)Session["selectedgroupes"];
        student_id_list=(ArrayList)Session["STUDENT_ID"];

        string select_string="SELECT student_name,student_id,student_nric,student_group FROM student_details WHERE student_group='"+groups[0].ToString().Trim()+"' ";
        for(int i=1;i<groups.Count;i++)
        {
            select_string+= " or student_group='"+groups[i].ToString().Trim()+"'";    
        }

        if(Session["STUDENT_ID"]!=null)
        {

        for(int i=0;i<student_id_list.Count;i++)
        {
            select_string+= " or student_id='"+student_id_list[i].ToString().Trim()+"'";    

        }
        }
        SqlConnection con = obj.getcon();
        con.Open();
        DataSet ds = new DataSet();

        SqlDataAdapter adapter = new SqlDataAdapter(select_string, con);
        adapter.Fill(ds);
        GridView2.DataSource = ds;
        GridView2.AllowSorting = false;
        GridView2.DataBind();
        con.Close();
    }

会是什么原因?它适用于我项目的另一个网格视图。请帮忙

【问题讨论】:

  • 设置 AllowSorting=false 时您想更正/发生什么?
  • 在其中一个正常工作的网格视图上的代码是什么样的?
  • 我想在gridview的底部显示新插入的记录。但现在它以排序格式显示。我想避免这种排序@FlopScientist
  • 不同的是,只是选择查询发生了变化。 @布莱恩·罗杰斯
  • 如果在数据绑定之前设置alloworting=false会怎样?

标签: c# asp.net gridview


【解决方案1】:

在 .aspx 页面中单击您的 gridview,然后按 f4。将弹出属性窗口。在那里你检查第 5 行(允许排序)。如果它是真的,那就是假的。有时代码隐藏代码由于时间问题而无法工作。如果它已经是假的,那么放置你的“GridView2.AllowSorting = false;”在数据源和数据绑定之间。

GridView2.DataSource = ds;
GridView2.AllowSorting = false;
GridView2.DataBind();

【讨论】:

  • 我已经按照你的建议做了。但即使它也不起作用@Sasidharan Chandran
  • 您是否检查了 .aspx 页面中的
  • 是的。我也试过这种方式。失败的 。是选择命令的问题吗? !我只是从表中选择记录到网格视图。 @Sasidharan Chandran
  • 在该查询中给出一个断点并复制整个查询并将其粘贴到此处。让我看看它是如何构建的。即使这样,如果查询有问题,我们也会尝试存储过程。跨度>
  • 如果您不想排序,请删除该 gridview2.allowsorting=false.Bco​​z 允许排序的默认值是 false。删除它并检查。您还会收到任何警告或错误。
【解决方案2】:

试试这个

string select_string="SELECT student_id,student_name,student_nric,student_group FROM student_details WHERE student_group='"+groups[0].ToString().Trim()+"' ";

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-04-24
    • 1970-01-01
    • 1970-01-01
    • 2022-06-26
    • 1970-01-01
    • 2019-04-15
    • 2013-04-30
    • 1970-01-01
    相关资源
    最近更新 更多