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