c# - 在数据绑定(bind)后对更新的 gridview 进行排序

标签 c# asp.net visual-studio-2008

这是我的代码中的问题部分。

 DataView view = ds.Tables[0].DefaultView;
 view.Sort = "user_id ASC, ip_address DESC;

 BalaiStatus.DataSource = view;
 BalaiStatus.DataBind();

 >>BalaiStatus.DataBind().Sort = "ip_address ASC";<<

BalaiStatus 将处理函数 BalaiStatus_RowDataBound。这段代码是为了消除gridview中的同一行。代码是:-

 string lastRow = "";


 protected void BalaiStatus_RowDataBound(object sender, GridViewRowEventArgs e)
 {

     if (e.Row.RowType == DataControlRowType.DataRow)
     {
         var thisRow = e.Row;

         if (thisRow.Cells[0].Text == lastRow)
         {
             e.Row.Visible = false;
        }
     }
     else {
          DataRowView view = (DataRowView)e.Row.DataItem;

          string login = Convert.ToString(view["ip_address"]);
          if (login == "")
          {
              e.Row.Cells[2].BackColor = Color.Red;        
          }
          else
          {             
              Global.rowCount = Global.rowCount + 1;

              e.Row.Cells[2].ForeColor = Color.White;
              e.Row.Cells[2].BackColor = Color.Green;

          }
          Global.allCount = Global.allCount + 1;
     }
     lastRow = thisRow.Cells[0].Text;
 }

所以,我需要的是,在剔除相同的行后,我想对gridview中的更新数据重新排序。请参阅>>代码<<..

任何人请帮助我解决这个问题。感谢您的意见或建议。感谢 Siti。

最佳答案

您应该在设置 gridview 的源之前过滤重复的行。这也将允许您在绑定(bind)网格之前进行排序。

这将取决于数据集 ds 的来源,您如何获取这些数据?

Rowdatabound 不应用于向表中删除/添加行,应该对数据集中的表存储执行此操作 ds

关于c# - 在数据绑定(bind)后对更新的 gridview 进行排序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17518881/

相关文章:

c# - C# 代码和非托管 C++ 库之间的双向通信

c# - WPF:绑定(bind)到 DataGrid 中行的 SelectedItem

c# - 无法实例化事件处理程序。输入 : Sitecore. Publishing.HtmlCacheClearer

asp.net - 代码隐藏文件中 RegisterClientScriptInclude 的语法错误

c# - 根据两个字段记住密码

asp.net mvc API 外部登录

c# - Rdlc tablix 列标题未在每一页上重复 "Repeat column header on every page"已检查

c# - 通过 Orchard CMS 中的 ASP.NET Web API 进行授权

python - Boost.Python 并导入一个 dll, "The specified module could not be found"

c# - ASP.NET 应用程序的单元测试配置