指定的参数(参数名: index)已超出有效值的范围
下面是页面代码:<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" Height="289px" Width="760px" GridLines="None" OnRowCommand="GridView1_RowCommand" DataKeyNames="DIA_ID" AllowPaging="True" OnPageIndexChanging="GridView1_PageIndexChanging" CssClass="GridViewStyle" OnRowDataBound="GridView1_RowDataBound1">
<Columns>
<asp:TemplateField HeaderText="日志编号" Visible="False">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("DIA_ID") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("DIA_ID") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="DIA_DATE" HeaderText="日期" >
下面是后台代码:
protected void GridView1_RowDataBound1(object sender, GridViewRowEventArgs e)
{
if (e.Row.Cells[1].Text.Trim().Length > 10)
{
e.Row.Cells[1].Text = e.Row.Cells[1].Text.Substring(0, 10);
}
}
出现以下异常:指定的参数(参数名: index)已超出有效值的范围。
--------------------编程问答-------------------- if(e.Row.RowType=DataControlRowType.DataRow)
{
if (e.Row.Cells[1].Text.Trim().Length > 10)
{
e.Row.Cells[1].Text = e.Row.Cells[1].Text.Substring(0, 10);
}
}
msn:hxd888666@163.com
hxd888666.cnblogs.com --------------------编程问答-------------------- 兄弟,我用了你的出现了这种错误:
编译器错误信息: CS0029: 无法将类型“System.Web.UI.WebControls.DataControlRowType”隐式转换为“bool”
能帮忙下吗 --------------------编程问答-------------------- 哦,解决了
if(e.Row.RowType=DataControlRowType.DataRow)
{
if (e.Row.Cells[1].Text.Trim().Length > 10)
{
e.Row.Cells[1].Text = e.Row.Cells[1].Text.Substring(0, 10);
}
}
少了个等于符号
补充:.NET技术 , ASP.NET