【问题标题】:Failure to bind the ArrayList to DataGrid无法将 ArrayList 绑定到 DataGrid
【发布时间】:2013-09-29 21:14:50
【问题描述】:

我不确定我在这里做错了什么。我想要做的是将 ArrayList 绑定到我在主页上拥有的 DataGrid。事情变得空白或只是出错。您可以提供的任何样品都会有很大帮助。我还需要将图像放在一个可点击的列中。那是硬编码的。谢谢。

在我的 default.aspx 页面中,我有...

"/asp:DataGrid>

然后在default.cs页面我有...

public class Share : Page
{
    protected TextBox SendExtraDetails;
    protected DataGrid DataGrid1;
            ......

    public void Page_Load(object sender, EventArgs e)
    {
            ArrayList alist = (ArrayList)Session["RSArrayList"];
            Session["RSArrayList"] = alist;

            DataGrid1.DataSource = alist;
            DataGrid1.DataBind();

    }
}

【问题讨论】:

标签: c# asp.net datagrid


【解决方案1】:

您需要runat="server" 来控制所有 ASP.Net 服务器。

此外,如果您不明确创建列,例如BoundColumn,则需要AutoGenerateColumns="True"

<asp:DataGrid ID="DataGrid1" AutoGenerateColumns="True" 
   runat="server"></asp:DataGrid>

请考虑将 GridView 与通用列表一起使用。 DataGrid 和 ArrayList 已过时。

【讨论】:

  • 是的,我希望我所在的公司有这个。他们没有。
【解决方案2】:

试试这个:

        ArrayList alist = (ArrayList)Session["RSArrayList"];

        DataGrid1.DataSource = alist;
        DataGrid1.DataBind();

【讨论】:

  • 这不是一回事吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-10-07
  • 2013-09-07
  • 2015-09-02
  • 1970-01-01
相关资源
最近更新 更多