我有代碼2列 背後我這一點:如何更改標題文本到網格視圖
protected void Page_Load(object sender, EventArgs e)
{
string connectionString = cs.getConnection();
string query = "SELECT ID , NAME FROM PROFITCATEGORIES";
using (SqlConnection myConnection = new SqlConnection(connectionString))
{
myConnection.Open();
SqlCommand command = new SqlCommand(query, myConnection);
using (SqlDataReader rdr = command.ExecuteReader())
{
GridViewCategory.DataSource = rdr;
GridViewCategory.DataBind();
GridViewCategory.Columns[0].HeaderText = "Header text"; // ERROR IS HERE
}
}
}
但是這給我一個錯誤:
Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
錯誤是在這條線:GridViewCategory.Columns [0] .HeaderText =「標題文本」;
我重新編輯我的帖子 – Krasimir