try this,
create a css class to hide the column
<style>
.hide {
display:none
}
</style>
Assign the css class to the
ItemStyle
and
HeaderStyle
<asp:GridView ID="GridView1" AutoGenerateColumns="false" runat="server" OnRowDataBound="GridView1_RowDataBound">
<Columns>
<asp:BoundField DataField="a1" HeaderText="a1" />
<asp:BoundField DataField="a2" HeaderText="a2" />
<asp:BoundField DataField="a3" HeaderText="a3" />
<asp:BoundField DataField="a4" ItemStyle-CssClass="hide" HeaderStyle-CssClass="hide" />
</Columns>
</asp:GridView>
Now you can get the value in
RowDatabound
event
protected void Page_Load(object sender, EventArgs e)
{
DataTable dt = new DataTable();
dt.Columns.Add("a1");
dt.Columns.Add("a2");
dt.Columns.Add("a3");
dt.Columns.Add("a4");
dt.Rows.Add(1, 2, 3, 4);
dt.Rows.Add(11, 22, 33, 44);
GridView1.DataSource = dt;
GridView1.DataBind();
}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
string a1 = e.Row.Cells[0].Text;
string a2 = e.Row.Cells[1].Text;
string a3 = e.Row.Cells[2].Text;
string a4 = e.Row.Cells[3].Text;
}
}