I am trying to hide the gridview coumn[1]. But it shows error like
Index was out of range. Must be non-negative and less than the size of
the collection parameter name:index.
How can I perform this. I surfed a lot in internet but I didnt get a proper solution. My code I mentioned below.It is a web based platform.
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
qry = "select Id,Name,Age,Sex,Dob from Sample where Code='123';
dr = conn.query(qry);
GridView1.DataSource = dr;
GridView1.DataBind();
GridView1.Columns[1].Visible = false;
}
}
In this same way column[0] is hiding. My grid view is
<asp:GridView ID="GridView1" HorizontalAlign="Center" runat="server"
onrowcommand="GridView1_RowCommand">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server"
CommandArgument='<%# Eval("ID")%>'>Delete</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>