关于隐藏列 指定的参数已超出有效值的范围的有关问题
关于隐藏列 指定的参数已超出有效值的范围的问题
各位大大,我想通过一个方法来指定隐藏列,但是运行的时候老是出错“指定的参数已超出有效值的范围”,请问各位大大问题出在哪里了呀,大概代码如下
后台代码
------解决方案--------------------
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Cells[0].Visible = false;
e.Row.Cells[1].Visible = false;
}
添加个if条件 代码放里面
各位大大,我想通过一个方法来指定隐藏列,但是运行的时候老是出错“指定的参数已超出有效值的范围”,请问各位大大问题出在哪里了呀,大概代码如下
- HTML code
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AutoGenerateColumns="False" DataKeyNames="id" CssClass="Fontsmall" onpageindexchanging="GridView1_PageIndexChanging" onrowdatabound="GridView1_RowDataBound" Width = "100%" onrowcommand="GridView1_RowCommand" onrowcreated="GridView1_RowCreated" > <Columns> <asp:TemplateField HeaderText = "设备情况1" > <ItemTemplate> <asp:Image ID="Image1" runat="server" ImageUrl ='<%# GetUrl( (string)Eval("qk1")) %>'/> </ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText = "设备情况2" > <ItemTemplate> <asp:Image ID="Image2" runat="server" ImageUrl ='<%# GetUrl( (string)Eval("qk2")) %>'/> </ItemTemplate> </asp:TemplateField> </Columns> </GridView>
后台代码
- C# code
protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e) { e.Row.Cells[0].Visible = false; e.Row.Cells[1].Visible = false; }
------解决方案--------------------
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Cells[0].Visible = false;
e.Row.Cells[1].Visible = false;
}
添加个if条件 代码放里面