Panel Control不会出现在GridView列中

时间:2009-11-18 22:57:27

标签: asp.net

其中一个GridView Column必须存储一个Panel Control(里面有一些控件)。问题是,代码不起作用,我的意思是,Panel没有出现在列中。

        Panel myPanel = new Panel();
        LinkButton zatw = new LinkButton();
        zatw.CommandName = "Accept";
        zatw.Text = "Accept";

        LinkButton odrz = new LinkButton();
        odrz.CommandName = "Deny";
        odrz.Text = "Deny";

        myPanel.Controls.Add(zatw);
        myPanel.Controls.Add(odrz);

        DataTable DT = new DataTable();
        DT.Columns.Add("Options", typeof(Panel));

        DataRow myRow = DT.NewRow();

        myRow1[0] = myPanel;

        DT.Rows.Add(myRow1);
        GridView1.DataSource = DT;
        GridView1.DataBind();
        ...

2 个答案:

答案 0 :(得分:1)

那是因为DT.Columns.Add("Options", typeof(Panel));不接受控件类型作为第二个参数。

从文档中。 DT.Columns的类型为

  

DataColumnCollection

实际上,确实有一个方法Add(String,Type)。但Type是列数据类型...它不接受控件。

示例:

Private Sub AddColumn()
    Dim columns As DataColumnCollection = _
        DataSet1.Tables("Orders").Columns
    Dim column As DataColumn = columns.Add( _
        "Total", System.Type.GetType("System.Decimal"))
    column.ReadOnly = True
    column.Unique = False
End Sub

在此示例中,正在创建名称为“Total”并键入“decimal”的列。

答案 1 :(得分:1)

我无法确切地告诉你到底要做什么,但我认为你不能以这种方式创建一个控制网格。为什么没有你的网格使用模板列,然后根据你绑定的数据调整模板,而不是像你想要的那样绑定到预建的UI?

相关问题