问题描述
下面是页面代码:<asp:GridViewID="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:TemplateFieldHeaderText="日志编号"Visible="False"><EditItemTemplate><asp:TextBoxID="TextBox1"runat="server"Text='<%#Bind("DIA_ID")%>'></asp:TextBox></EditItemTemplate><ItemTemplate><asp:LabelID="Label1"runat="server"Text='<%#Bind("DIA_ID")%>'></asp:Label></ItemTemplate></asp:TemplateField><asp:BoundFieldDataField="DIA_DATE"HeaderText="日期">下面是后台代码:protectedvoidGridView1_RowDataBound1(objectsender,GridViewRowEventArgse){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.comhxd888666.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);}}少了个等于符号