one of the GridView Column has to store a Panel Control (with some Controls inside). The problem is, that code doesn't work, I mean, the Panel doesn't appear inside the column.
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.Data开发者_如何学CBind();
...
That's because DT.Columns.Add("Options", typeof(Panel));
won't accept a control type as the second argument.
From the documentation. DT.Columns is of type
DataColumnCollection
that, indeed, has a method Add(String, Type) as you used it. But the Type is the column data type... it does not accept a control.
Example:
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
In this example, a column of name "Total" and type "decimal" is being created.
I can't really tell what you are trying to do exactly but I don't think you can create a grid out of controls in this manner. Why don't have your grid use a template column and then adjust the template based on the data you bind to instead of binding to a prebuilt UI like you are trying to do?
精彩评论