私はこれを持っている背後にあるコードに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 = "Header text";