返回一个泛型集合 然后将这个泛型集合 foreach 循环显示在页面上    可以代码前置的 或者后置也行  哈哈  麻烦 帮帮忙  我菜菜啊

解决方案 »

  1.   

    假设返回泛型集合的方法是GetData():<asp:GridView ID="GridView1" runat="server" >
    </asp:GridView><script runat="server">
    protected void Page_Load(object sender, EventArgs e)
    {
    GridView1.DataSource = GetData();
    GridView1.DataBind();
    }
    </script>
      

  2.   

    感谢楼上的,但是我不想用控件我 你教我怎么将返回的泛型集合用一个Table显示出来    
      

  3.   

    List<T> lst=new List<T>();
    foreach(T t in lst)
    {
    }
      

  4.   

    GridView1 生成以后就是 table 
      

  5.   

    直接来   User表  name和age两个字段
    List<User>找出来了现在把它显示在页面上,上一个HTML Table  怎么把 name和age显示出来 而且是很多条
      

  6.   

    我写的  献丑了  List<Dictionary<string, List<Categories>>> list = CategoriesManage.GetCategories();//获取泛型集合
                Dictionary<string, List<Categories>> dic = list[0];
                    foreach (string s in dic.Keys)
                    {
                        List<Categories> list1 = dic[s];
                        Table tb = new Table();
                        for (int i = 0; i <= 1; i++)
                        {
                            if (i == 0)
                            {
                                TableRow tr = new TableRow();
                                tb.Rows.Add(tr);
                                TableCell td = new TableCell();
                                tr.Cells.Add(td);
                                td.ToolTip = s;
                                td.Text = s+"<hr>";
                                if (td.Text.Length > 4)
                                {
                                    td.Text = td.Text.Substring(0, 4) + "...<hr>"; ;
                                }
                                td.Text="<B>"+td.Text+"</B>";
                            }
                            else
                            {
                                int a = 0; 
                                TableRow tr1=null;
                                foreach (Categories c1 in list1)
                                {
                                    TableCell td1 = new TableCell();
                                    if (a % 3 == 0)
                                    {
                                        tr1 = new TableRow();
                                        tb.Rows.Add(tr1);
                                        tr1.Cells.Add(td1);
                                        td1.ToolTip = c1.Name;
                                        td1.Text = c1.Name;
                                        if (td1.Text.Length > 4)
                                        {
                                            td1.Text = td1.Text.Substring(0, 4);
                                        }
                                        
                                    }
                                    else
                                    {
                                        tr1.Cells.Add(td1);
                                        td1.ToolTip = c1.Name;
                                        td1.Text = c1.Name;
                                        if (td1.Text.Length > 4)
                                        {
                                            td1.Text = td1.Text.Substring(0, 4);
                                        }
                                    }
                                    td1.Text = "<a href='BookList.aspx?typeid="+c1.Id+"'>" + td1.Text + "</a>";
                                    a++;
                                }
                            }
                        }
                        this.P1.Controls.Add(tb);                    if (IsPostBack)//保持单选按钮的状态
                        {
                            try
                            {
                                string rdo = ViewState["rdo"].ToString();
                                if (rdo == "Author")
                                {
                                    this.Author.Checked = true;
                                }
                            }
                            catch (Exception)
                            {
                            }
                        }                    foreach (string k in Session.Keys)
                        {
                            if (k == "CurrentUser")
                            {
                                this.PNoLogin.Visible = false;
                                this.pLoginUser.Visible = true;
                                Users u = Session["CurrentUser"] as Users;
                                this.lbLoginName.Text = u.LoginId;
                                this.lbLoginType.Text = u.UserRoleId.Name;
                            }
                        }
                   
                }