Conditionally Hide Select Column of GridView ?

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
 
M

Mark Rae [MVP]

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;
 
L

Luqman

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;
 
M

Mark Rae [MVP]

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";
}
}
 
L

luqman

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";
}
}
 

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,768
Messages
2,569,574
Members
45,050
Latest member
AngelS122

Latest Threads

Top