【发布时间】:2014-05-30 03:46:53
【问题描述】:
我有一个从 SQL 数据源填充的 gridview。
每当我打开页面时,我都会在 gridview rowdatabound 中收到 stackoverflow 异常。
是什么导致了问题?
Search.aspx:
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False" CellPadding="4" DataSourceID="ConsultsSQLDataSource" ForeColor="#333333" GridLines="None" OnRowDataBound="GridView1_RowDataBound">
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:BoundField DataField="DATA" HeaderText="Data" SortExpression="DATA" />
<asp:BoundField DataField="LOCAL" HeaderText="Local" SortExpression="LOCAL" />
<asp:BoundField DataField="URGENCIA" HeaderText="Urgencia" SortExpression="URGENCIA" />
<asp:BoundField DataField="ESTADO" HeaderText="Estado" SortExpression="ESTADO" />
<asp:HyperLinkField HeaderText="Pagamento" NavigateUrl="a" Text="Link" Visible="False" />
<asp:BoundField DataField="IDPAGAMENTO" SortExpression="IDPAGAMENTO" Visible="False" />
</Columns>
</asp:GridView>
代码隐藏:
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
string value = e.Row.Cells[2].Text;
switch(value)
{
case "3":
e.Row.Cells[3].Text = "Waiting Payment";
HyperLinkField hp = (HyperLinkField)GridView1.Columns[4];
GridView1.Columns[4].Visible = true;
GridView1.Columns[5].Visible = true;
hp.NavigateUrl = "~/Account/Payments/Payment?PaymentID=" + e.Row.Cells[5].Text; //Exception occurs here
hp.Text = "Pay";
e.Row.Cells[4].Visible = true;
break;
}
}
}
【问题讨论】:
-
我得到的唯一信息是:System.Data.dll 中发生了“System.StackOverflowException”类型的未处理异常
-
是的,我从 e.Row.Cells[5].Text 中正确获取了值
-
如果您遵循以下操作,它会改变什么: hp.NavigateUrl = string.Format("~/Account/Payments/Payment?PaymentID={0}", + e.Row.Cells[5].文字;)
-
只需在您的 GridView1_RowDataBound 方法上放置一个调试器,然后查看它在哪一行给出错误。
标签: c# asp.net gridview stack-overflow