解决过江朋友的问题- -怎样把DataSet转换成ArrayList

1.绑定时候~~建议用泛型~~不过建议过江朋友的要求~~
2.ArrayList用链表的结构就是myAl 代表行,里面的myAl 代表行中的列,这样就可以了

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="dataset.aspx.cs" Inherits="dataset" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    
<title>无标题页</title>
</head>
<body>
    
<form id="form1" runat="server">
    
<div>
        
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" OnRowDataBound="GridView1_RowDataBound">
            
<Columns>
                
<asp:TemplateField>
                
<ItemTemplate>
                
                
<label><%# ((ArrayList)myAl[0])[0%></label>
               
                
</ItemTemplate>
                
</asp:TemplateField>
                
                
                                
<asp:TemplateField>
                
<ItemTemplate>
                
                
<label><%# ((ArrayList)myAl[0])[1%></label>
               
                
</ItemTemplate>
                
</asp:TemplateField>
                
                
                
                                
<asp:TemplateField>
                
<ItemTemplate>
                
                
<label><%# ((ArrayList)myAl[0])[2%></label>
               
                
</ItemTemplate>
                
</asp:TemplateField>
            
</Columns>
        
</asp:GridView>
    
    
</div>
        
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" />
    
</form>
</body>
</html>

      ArrayList myAl = new ArrayList();
            
foreach (DataRow dr in myDataSet.Tables[0].Rows)
            
{
                ArrayList s 
= new ArrayList();
                
foreach (DataColumn dn in myDataSet.Tables[0].Columns)
                
{
                    
if (dr[dn.ColumnName].ToString() =="")
                        
continue;
                      s.Add(dr[dn.ColumnName]);

                }

                myAl.Add(s);
            
            }

posted @ 2007-05-12 11:24  苹果王子  阅读(1317)  评论(3编辑  收藏  举报