我正在尝试创建一个包含单元格内部按钮的表(所有动态)。 当我创建按钮并尝试将其添加到单元格时,我没有看到任何按钮,只有他的内部字符串 - >单元格内的“System.Web.UI.WebControls.TableCell”。
以下代码:
public void DynamicDataTable()
{
string CurrentGame = (string)Session["theItemIdSessions"];
XmlDocument myDoc = new XmlDocument();
myDoc.Load(MapPath("XMLFile.xml"));
XmlNodeList TheGame = myDoc.SelectNodes("games/game[@id='" + CurrentGame + "']/question");
//יצירת טבהל דינאמית
DataTable gameTable = new DataTable();
gameTable.Columns.Add("פריט השוואה 1", typeof(string));
gameTable.Columns.Add("סימן היחס", typeof(string));
gameTable.Columns.Add("פריט השוואה 2", typeof(string));
gameTable.Columns.Add("עריכה", typeof(string));
gameTable.Columns.Add("מחיקה", typeof(string));
XmlNodeList items = myDoc.SelectNodes("games/game[@id='" + CurrentGame + "']/question/item");
int firstItem = 0;
int secondItem = 1;
for (int i = 0; i < TheGame.Count; i++)
{
Button button = new Button();
button.Text = "עריכה";
button.Width = 80;
button.Height = 10;
button.Click += new EventHandler(bt_Click);
TableCell btnCell = new TableCell();
btnCell.Controls.Add(button);
gameTable.Rows.Add(items.Item(firstItem).InnerXml, "a", items.Item(secondItem).InnerXml, btnCell, "delete");
firstItem += 2;
secondItem += 2;
}
}