1

我有一个可用的座位DataGrid,每个都有一个复选框可以保留座位。在按钮单击事件,若点击复选框,我加入行的内容到一个ArrayList,然后重定向到确认页面之前添加的ArrayList到会话:将多维ArrayList绑定到Gridview

protected void Reserve_Click(object sender, EventArgs e) 
{ 
    { 
     ArrayList seatingArreaList = new ArrayList(); 
     for (int i = 0; i < GridView1.Rows.Count; i++) 
     { 
      Guid SeatId = (Guid)GridView1.DataKeys[i][0]; 
      CheckBox cbReserve = (CheckBox)GridView1.Rows[i].FindControl("cbReserve"); 
      Label lblSection = (Label)GridView1.Rows[i].FindControl("lblSection"); 
      Label lblRow = (Label)GridView1.Rows[i].FindControl("lblRow"); 
      Label lblPrice = (Label)GridView1.Rows[i].FindControl("lblPrice"); 

      if (cbReserve.Checked) 
      { 
       string tempRowInfo = lblSection.Text + "|" + lblRow.Text + "|" + lblPrice.Text; 
       seatingArreaList.Add(tempRowInfo); 
      } 
     } 
     // Add the selected seats to a session 
     Session["Seating"] = seatingArreaList; 
    } 
    Response.Redirect("Confirm.aspx?concertId=" + Request.QueryString["concertId"]); 
} 

在确认页面,我喜欢将这个数组分开并将它绑定到其各个列中的另一个gridview。

在确认页面上,存在一个会话,该会话有三个以管道分隔的列,我正努力将其拆分并将其绑定到确认网格。

请帮忙!

回答

3

这可能会更容易创建一个DataTable,然后将其添加到会话变量。一旦重定向到确认页面,只需将GridView绑定到从会话变量中提取的DataTable即可。

protected void Reserve_Click(object sender, EventArgs e) 
    { 
     DataTable dt = new DataTable(); 
     dt.Columns.Add("Section"); 
     dt.Columns.Add("Row"); 
     dt.Columns.Add("Price"); 

     { 
      ArrayList seatingArreaList = new ArrayList(); 
      for (int i = 0; i < GridView1.Rows.Count; i++) 
      { 
       Guid SeatId = (Guid)GridView1.DataKeys[i][0]; 
       CheckBox cbReserve = (CheckBox)GridView1.Rows[i].FindControl("cbReserve"); 
       Label lblSection = (Label)GridView1.Rows[i].FindControl("lblSection"); 
       Label lblRow = (Label)GridView1.Rows[i].FindControl("lblRow"); 
       Label lblPrice = (Label)GridView1.Rows[i].FindControl("lblPrice"); 

       if (cbReserve.Checked) 
       { 
        DataRow dr = dt.NewRow(); 
        dr["Section"] = lblSection.Text; 
        dr["Row"] = lblRow.Text; 
        dr["Price"] = lblPrice.Text; 
        dt.Rows.Add(dr); 
       } 
      } 
      // Add the selected seats to a session 
      Session["Seating"] = dt; 
     } 
     Response.Redirect("Confirm.aspx?concertId=" + Request.QueryString["concertId"]); 
    } 
+0

谢谢!有意义使用该页面上的数据表。我试图在确认页面上使用它,并将数组拆分成它。当然,现在我不需要阵列。谢谢 :-) – Neil 2009-12-07 15:01:33

0
var q = from dto in seatingArreaList 
    let z = dto.Split("|".ToCharArray()) 
    select z; 

,然后就冰q到电网。