Hide GridView column

D

DavidC

I have a GridView that I want to hide a whole column based on a condition
known before it is Databound. Is the best place to do this in RowDatabound
or in PreRender or ??? Thanks.
 
M

Mark Rae [MVP]

I have a GridView that I want to hide a whole column based on a condition
known before it is Databound. Is the best place to do this in
RowDatabound
or in PreRender or ??? Thanks.

I wouldn't do either...

Presumably you have a server-side method which does the databinding and
which you call as and when required e.g.

protected void Page_Load(object sender, EventArgs e)
{
if(!IsPostBack)
{
BindData();
}
}

private void BindData()
{
DataSet MyDS = <fetch a DataSet from the DAL/BOL>;
MyGridView.DataSource = MyDS;
MyGridView.DataBind();
MyGridView.Columns[3].Visible = false; // hide the column
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,562
Members
45,038
Latest member
OrderProperKetocapsules

Latest Threads

Top