代码之家  ›  专栏  ›  技术社区  ›  CodexArcanum

所选行在GridView排序后不更改

  •  1
  • CodexArcanum  · 技术社区  · 15 年前

    我对网格视图有一个奇怪的问题。我设置了一个选择列,并允许排序。如果我选择了一行,然后对网格排序,那么所选内容将保持原位,网格也将排序。也就是说,突出显示的行已更改,但所选内容的索引似乎没有更改。

    在观察表中的网格时,似乎所选索引属性实际上保持不变,但所选数据键正在更改。

    我很困惑,一直无法追查为什么会这样,有什么想法吗?

    2 回复  |  直到 15 年前
        1
  •  2
  •   Matthew Jones    15 年前

    我发现 a change request for this exact issue 声明如下:

    我们不是故意的 跨类别的选择轨迹, 更新、删除等。此部件将 不可更改。

    看起来您需要一种不同的方法来跟踪跨排序的选定行。

        2
  •  1
  •   Johan    15 年前

    意外的是,我找到了一个解决这个问题的方法,也许不是那么甜蜜,但无论如何,我得到了我想要的东西:) 在GridView中\u prerender load事件

    受保护的void gridview1_prerender(对象发送器,事件参数e) { //如果文本太长,则重新构造该文本。

            if (GridView1.Controls.Count != 0)
            {
                foreach (GridViewRow r in GridView1.Controls[0].Controls)
                {
                    foreach (TableCell tc in r.Controls)
                    {
                        if (tc.Text != "" && tc.Text.Length > 39)
                        {
                            tc.Text = tc.Text.Substring(0, 39) + " ...";
                        }
                    }
                }
            }
    
            // here is the where the magic happens :)
            if (GridView1.SelectedRow != null)
            {
                GridViewRow row = GridView1.SelectedRow;
                if (row.Cells.Count > 1)
                {
                    //Here I pick the p.keyID
                    SetOrderData(Convert.ToInt32(row.Cells[1].Text));
    
                    this.LabelDebug.Text = row.Cells[1].Text;
                }
            }
        }