【发布时间】:2015-11-26 08:24:35
【问题描述】:
我想绑定数据 gridview 并将数据 '0' 更改为 '-' 。 但是错误:指定的参数超出了有效值的范围。参数名称:索引
代码asp
<asp:GridView ID="GridView1" runat="server"
AutoGenerateColumns="False" AllowPaging="true"
OnRowCreated="GridView1_RowCreated"
OnRowDataBound="GridView1_RowDataBound" >
<Columns>
<asp:BoundField DataField="amt" HeaderText="Total"
DataFormatString="{0:#,##0.00000}" ItemStyle-HorizontalAlign="Right" />
</Columns>
</asp:GridView>
C#代码
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
string sAmt = DataBinder.Eval(e.Row.DataItem, "amt").ToString();
if (sAmt == "0.00000")
{
e.Row.Cells[10].Text = "-"; <<< Line Error
}
}
}
如果字段 AMT 显示 0。
我希望将“0”改为“-”。
请帮帮我。提前感谢您的时间。 ;)
【问题讨论】:
-
gridview 中有 10 个单元格吗?请显示标记
标签: c# asp.net gridview error-handling rowdatabound