Conditionally Hide Select Column of GridView ?

  • Thread starter Thread starter Luqman
  • Start date Start date
L

Luqman

I have populated the Child Accounts and Parent Accounts in a Grid View
Control, I want to hide the Select Column of Parent Accounts, but not the
Child Accounts, is it possible ?

I am using VS 2005 ?

Best Regards,

Luqman
 
I have populated the Child Accounts and Parent Accounts in a Grid View
Control, I want to hide the Select Column of Parent Accounts, but not the
Child Accounts, is it possible ?

I am using VS 2005 ?

Not sure what you mean by "Child Accounts" and "Parent Accounts"...

When you say you want to "hide" the column, does that mean that you still
want it to be rendered to the client but invisible, or you don't want it to
be rendered at all...?

I'm guessing the latter, in which case:

MyGridView.Columns[n].Visible = false;
 
No, I mean, I want to hide select Column Cell for the particular Rows, for
example: it should be visible for row no. 1 but hide for row no. 2

I want this to be done when the gridview is filling, if field tag='Y' then
gridview select column cell should be visible otherwise it should be hide or
disable or user should not be able to click on Select of that particular
Row.

Any idea please ?

Best Regards,

Luqman


Mark Rae said:
I have populated the Child Accounts and Parent Accounts in a Grid View
Control, I want to hide the Select Column of Parent Accounts, but not the
Child Accounts, is it possible ?

I am using VS 2005 ?

Not sure what you mean by "Child Accounts" and "Parent Accounts"...

When you say you want to "hide" the column, does that mean that you still
want it to be rendered to the client but invisible, or you don't want it to
be rendered at all...?

I'm guessing the latter, in which case:

MyGridView.Columns[n].Visible = false;
 
No, I mean, I want to hide select Column Cell for the particular Rows, for
example: it should be visible for row no. 1 but hide for row no. 2

Ah, so you don't actually want to hide the column (as per your subject), but
rather individual cells in a column...
I want this to be done when the gridview is filling, if field tag='Y' then
gridview select column cell should be visible otherwise it should be hide
or
disable or user should not be able to click on Select of that particular
Row.

<asp:GridView ID="MyGridView" runat="server"
OnRowDataBound="MyGridView_RowDataBound" ...>
...
</asp:GridView ID>

protected void MyGridView_RowDataBound(object sender, GridViewRowEventArgs
e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Cells[0].Controls[0].Visible = e.Row.Cells[1].Text == "Y";
}
}
 
Hi Mark,

Thats what exactly I wanted,thanks very much.

Best Regards,

Luqman

Mark Rae said:
No, I mean, I want to hide select Column Cell for the particular Rows, for
example: it should be visible for row no. 1 but hide for row no. 2

Ah, so you don't actually want to hide the column (as per your subject), but
rather individual cells in a column...
I want this to be done when the gridview is filling, if field tag='Y' then
gridview select column cell should be visible otherwise it should be hide
or
disable or user should not be able to click on Select of that particular
Row.

<asp:GridView ID="MyGridView" runat="server"
OnRowDataBound="MyGridView_RowDataBound" ...>
...
</asp:GridView ID>

protected void MyGridView_RowDataBound(object sender, GridViewRowEventArgs
e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Cells[0].Controls[0].Visible = e.Row.Cells[1].Text == "Y";
}
}
 
Back
Top