1
对于c#,asp.net和Visual Studio,我很新,我的平常阵容是Java与Eclipse(和Captain Casa)。C#ASP.net使用ImageButton填充GridView
所以我的实际问题是以下几点。
DataTable lowerTable = new DataTable();
// create columns
for (int i = 0; i < logic.gameSize; i++)
{
lowerTable.Columns.Add();
}
for (int j = 0; j < logic.gameSize; j++)
{
// create a DataRow using .NewRow()
DataRow row = lowerTable.NewRow();
// iterate over all columns to fill the row
for (int i = 0; i < logic.gameSize; i++)
{
ImageButton button = new ImageButton();
button.ImageUrl = "";
button.AlternateText = logic.getValue(logic.bord.getLowerBord()[j, i].getFigur()).ToString();
row[i] = button;
}
// add the current row to the DataTable
lowerTable.Rows.Add(row);
LowerField.Controls.Add(new ImageButton());
LowerField.DataSource = lowerTable;
try
{
LowerField.DataBind();
}
catch (Exception ex)
{
System.Diagnostics.Debug.Write(ex.ToString());
}
}
}
进出口创造一个DataTable,以填补我的GridView ......但结果不是预期的电网全按键的,但充满了文字网格:System.Web.UI.WebControls.ImageButton。 我已经尝试使用全球化的按钮,但这也没有帮助。 我忽略了一个简单的机械师吗?我实际上找不到任何适合Google的东西,或者至少没有符合我的实际需求的东西。
希望你可以帮助 谢谢 Bienenwolf
你需要使用ASP.NET控件,比如'GridView'或者'ListView'(或者其他众多的控件)。如果你想动态地做,[这是一个链接](https://code.msdn.microsoft.com/AddDynamicallyControlstoGri-d74fe84f)。否则,就像在控件的ASPX代码中设置一个'ItemTemplate' [像这样](https://msdn.microsoft.com/en-us/library/Bb288031.aspx) - 只需更改模板字段包含一个'ImageButton'。 – TestWell
您的第一个链接非常有用,谢谢。我现在如何修复它:使用OnDataBound函数添加控件。 – Bienenwolf