473,387 Members | 1,619 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Make one cell in gridview invisible?

Jo
Hi all,

I have a gridview displaying a dataset and some buttons. When a certain
cell of this datasetrow is empty, I want a button in that row to be
visible, otherwise no button should be shown in that row.

I'm trying to make this work all day, but it's not going to work.

I tried this in the rowCreated event. I am able to find the right row
and cell in this row (as a datarow), but now the right gridview
row-cell should be made visible.

This is what I have right now (C#):

protected void supplierFilesGrid_RowCreated(object sender,
GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
DataRowView drView = (DataRowView)e.Row.DataItem;
DataRow drRow = drView.Row;

if (drRow[2].ToString() == "NEW")
{
int i = e.Row.RowIndex; //
this works fine, after this I get an error:
//grid.Rows[i].Cells[1].Visible = false; //
argumentOutOfRangeException...
(sender as GridView).Rows[i].Cells[1].Visible =
false;
}
}
}

Has anyone a suggestion how to make this work?

Thanks in advance!

Regards,
Jo

Apr 6 '06 #1
11 14978
I believe you want the grid.ItemDataBound event

Apr 6 '06 #2
Jo
Hi,
Maybe I do, but what should I do within this event?

Regards,
Jo

Apr 6 '06 #3

Here is a snippet of code I have in this event to get you started.

e.Item.Cells.Item(4).ToolTip = e.Item.Cells.Item(5).Text

Apr 6 '06 #4
Jo
Hi,
Thanks for your quick reply! You gave me the right hint to continue
this 'problem'.

A gridview doesn't have an ItemDataBound event, I used the RowDataBound
event and it works! But not completely as hoped: the data/buttons in
the columns behind the 'Invisible' column move 1 column to the left,
filling the space of the 'invisible' column. That's not what I need,
this column should be left empty, 'not replaced'...
That's the only issue left now. Any solution to that?

protected void grid_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
DataRowView drView = (DataRowView)e.Row.DataItem;
DataRow drRow = drView.Row;

if (drRow[6].ToString() != "")
{
int i = e.Row.RowIndex;
e.Row.Cells[7].Visible = false;
}
}
}

Regards,
Jo

Apr 7 '06 #5
"Jo" <jo**************@organon.com>'s wild thoughts were
released on 7 Apr 2006 00:49:27 -0700 bearing the following
fruit:
Hi,
Thanks for your quick reply! You gave me the right hint to continue
this 'problem'.

A gridview doesn't have an ItemDataBound event, I used the RowDataBound
event and it works! But not completely as hoped: the data/buttons in
the columns behind the 'Invisible' column move 1 column to the left,
filling the space of the 'invisible' column. That's not what I need,
this column should be left empty, 'not replaced'...
That's the only issue left now. Any solution to that?
You don't want to remove the cell, only it's contents.

J
protected void grid_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
DataRowView drView = (DataRowView)e.Row.DataItem;
DataRow drRow = drView.Row;

if (drRow[6].ToString() != "")
{
int i = e.Row.RowIndex;
e.Row.Cells[7].Visible = false;
}
}
}

Regards,
Jo

Jan Hyde (VB MVP)

--
Divorce: Going through a change of wife. (Henny Youngman)

Apr 7 '06 #6
Jo
Hi,

You don't want to remove the cell, only it's contents.


I thought I wasn't removing anything, just hiding
("e.Row.Cells[7].Visible = false"),
still the content of remaining cells in that row is taking the place of
the content of the 'invisible' cell.

So, maybe you can be more clear about this?

Thank you!
Jo

Apr 7 '06 #7
"Jo" <jo**************@organon.com>'s wild thoughts were
released on 7 Apr 2006 02:30:49 -0700 bearing the following
fruit:
Hi,

You don't want to remove the cell, only it's contents.


I thought I wasn't removing anything, just hiding
("e.Row.Cells[7].Visible = false"),
still the content of remaining cells in that row is taking the place of
the content of the 'invisible' cell.

So, maybe you can be more clear about this?


'I want a button in that row to be visible, otherwise no
button should be shown in that row'

So change the visible propery of the button to false.

Jan Hyde (VB MVP)

--
Could you say that a cannibalistic lion might swallow his pride?
(Ken Shurget)

Apr 7 '06 #8
Jo
Hi,

So change the visible propery of the button to false.


First, I didn't know how to do that, but I've tried this code (see
below), and I got an ArgumentOutOfRangeException!
I guess that the row which gives the GridViewRowEventArgs haven't been
created in the GridView at that time, the row before this one does exit
in de Gridview, the current one not...
Maybe I have to try to do this in the rowcreated_event???

protected void grid_RowDataBound(object sender, GridViewRowEventArgs e)

{
if (e.Row.RowType == DataControlRowType.DataRow)
{
DataRowView drView = (DataRowView)e.Row.DataItem;
DataRow drRow = drView.Row;

if (drRow[6].ToString() != "")
{
int i = e.Row.RowIndex;
//e.Row.Cells[7].Visible = false; REPLACED BY:
grid.Rows[i].Controls[7].Visible = false; ////////
Gives an ArgumentOutOfRangeException!
}
}
}

Apr 7 '06 #9
Jo
I got the same problem in the rowcreated_event...

And tried "e.Row.Cells.RemoveAt(7);" in stead of
"e.Row.Cells[7].Visible = false", but that gives (visually) the same
results
That's something I can't explain: removing and making invisible isn't
the same!

I'm going of to enjoy my weekend. Hopefully someone can give me a
straight answer and a solution to my 'problem'.

Enjoy!
Jo

Apr 7 '06 #10
It's not Controls[7]. Similar to Cell[7].Controls[0]

Apr 7 '06 #11
Jo
Thanks for your support!
Now it's working:

e.Row.Cells[7].Controls[1].Visible = false;

Thank you!
Jo

Apr 10 '06 #12

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Matt | last post by:
Are there any settings to make a page invisible to the user until certain time? For example, I want mypage.html is invisible to the user until 12:00am. But mypage.html is already in the IIS server....
1
by: PCB | last post by:
Hi all, Not sure if this is possible, but can I change the controls of a command button on a per record bases in a subform. In my case, I would like to make a command button visible only if...
3
by: Richard | last post by:
After printing a userlist to a Datagrid i want some names not to be shown. I want to know how i can make a entire datagrid row invisible. I suspect its something with the OnItemDatabound but i am...
0
by: Roy | last post by:
What is the best way to approach this problem? I have a datagrid with an imagebutton. When one clicks the imagebutton it triggers an onClick sub which makes column 9 (a user control) visible or...
6
by: Selden McCabe | last post by:
I have a form with a bunch of image buttons. When the user moves the mouse over a button, I want to do two things: 1. change the Imagebutton's picture, and 2. make another control visible. I'm...
3
by: david | last post by:
I have posted my question before. It seems that I can not find the solution. The question: I have datasource, say, ds which is bounded to a datagrid, dg. Assume that ds have 5 columns,...
1
by: indoo | last post by:
Javascript to make a character invisible in a texbox on onfocus event. Thanks in Advance.
0
by: sony.m.2007 | last post by:
Hi, I'm creating a combox control in XAML(WPF) and loading the items from a table in sql server. There are four items in the combobox.I need to hide an item in the combobox and to show three...
1
by: riyazuddin | last post by:
how to make a character invisible when the user is typing from keyboard in linux
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.