【发布时间】:2015-10-05 07:57:42
【问题描述】:
在我的情况下,我的网格视图可以包含普通文本或超链接。我想获得这些字段的值。到目前为止,我已经尝试过
DataTable detailTable = new DataTable();
for (int i = 0; i < gvTransactionDetails.Columns.Count; i++)
{
detailTable.Columns.Add(gvTransactionDetails.HeaderRow.Cells[i].Text.ToString());
}
foreach (GridViewRow gvrow in gvTransactionDetails.Rows)
{
DataRow dr = detailTable.NewRow();
for (int j = 0; j < gvTransactionDetails.Columns.Count; j++)
{
Control hyperLink = gvrow.Cells[j].Controls[0] as LiteralControl;
if (hyperLink != null)
{
dr[j] = ((LiteralControl)gvrow.Cells[j].Controls[0]).Text.ToString();
}
else
{
dr[j] = gvrow.Cells[j].Text.ToString();
}
}
detailTable.Rows.Add(dr);
}
我面临的问题是,每一行中的第一个单元格是一个超链接,其余所有单元格只包含文本值,只有在 foreach 循环的第一次迭代之后,我才得到“指定的参数超出了有效值的范围。 参数名称:index”异常。
知道如何解决吗?
【问题讨论】:
-
你可以为 GridView 发布你的 HTML 代码吗?