【问题标题】:datagrid rows to save in collection and show on another page asp.net数据网格行保存在集合中并显示在另一个页面 asp.net
【发布时间】:2012-05-10 11:44:16
【问题描述】:

我的页面中有四列多行的网格 Userid 用户名 stateid 和 statename

我应该使用哪个集合来使用会话将数据发送到另一个页面 我的代码是

string[] strArray = new string[] {}; 

        foreach (GridViewRow gr in gvCompany.Rows)
        {
           strArray =new string[4] {new[] {gr.Cells[0].Text}.ToString(), new[] {gr.Cells[1].Text}.ToString(), new[] {gr.Cells[2].Text}.ToString(),new[] {gr.Cells[3].Text}.ToString()};


        }
        Session["List"] = strArray;
        Response.Redirect("Tid.aspx?Mode=List");

在 tid 页面上我的代码是

string[] ls = new string[] { }; 
                  ls =(string[]) Session["List"];
                foreach (string st in ls )
                {
                    //get each cell
                }

但 st 的值是 system.string 而不是 value

【问题讨论】:

    标签: asp.net session collections datatable rows


    【解决方案1】:

    不建议使用字符串[],因为将来添加的字段越多,保持字段和索引关系无错误就越困难..

    您可以创建一个适当的类对象,例如。 Company 并将 List 传递给其他类,List 位于 System.Collections.Generic 命名空间中。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-02-07
      • 2021-12-17
      • 2016-11-08
      • 1970-01-01
      • 2023-04-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多