各位程序员,我正在尝试获取 Gridview 的最后一列(已绑定到某个 SQL 数据库)中的值,然后根据该单元格的值可能用生成的超链接替换该单元格的内容。到目前为止我的代码:
protected void Page_Load(object sender, EventArgs e)
{
/* Load the Required Data */
StrCommand="SELECT "+ Request.QueryString["Cols"] + " FROM " + Request.QueryString["Category"];
SqlConnection myConnection = new SqlConnection();
myConnection.ConnectionString = "Data Source=localhost;" + "Initial Catalog=Categories; Integrated Security=SSPI";
SqlCommand myCommand = new SqlCommand(StrCommand, myConnection);
myConnection.Open();
SqlDataReader DataReader1 = myCommand.ExecuteReader();
ProductList.DataSource = DataReader1;
ProductList.DataBind();
myConnection.Close();
/* Post-binding modifications are now applied to the Grid View */
/* Generate the column containing the add-to-cart buttons */
for (int j = 0; j < ProductList.Rows.Count-1; j++)
{
int id_holder = int.Parse(ProductList.Rows[j].Cells[ProductList.Columns.Count-1].Text);
}
}
不幸的是,这段代码失败了,我得到了这个错误:
Specified argument was out of the range of valid values. Parameter name: index
任何想法表示赞赏,
狮子座