473,779 Members | 2,035 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 supplierFilesGr id_RowCreated(o bject sender,
GridViewRowEven tArgs e)
{
if (e.Row.RowType == DataControlRowT ype.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; //
argumentOutOfRa ngeException...
(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 15011
I believe you want the grid.ItemDataBo und 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.It em(4).ToolTip = e.Item.Cells.It em(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_RowDataBou nd(object sender, GridViewRowEven tArgs e)
{
if (e.Row.RowType == DataControlRowT ype.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_RowDataBou nd(object sender, GridViewRowEven tArgs e)
{
if (e.Row.RowType == DataControlRowT ype.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.Cell s[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.Cell s[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 ArgumentOutOfRa ngeException!
I guess that the row which gives the GridViewRowEven tArgs 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_even t???

protected void grid_RowDataBou nd(object sender, GridViewRowEven tArgs e)

{
if (e.Row.RowType == DataControlRowT ype.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 ArgumentOutOfRa ngeException!
}
}
}

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

And tried "e.Row.Cells.Re moveAt(7);" in stead of
"e.Row.Cell s[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

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

Similar topics

3
1674
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. any ideas? thanks!
1
4209
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 certain fields in a table are a certain value. The buttons are adjacent to each record (i.e. - if there are 5 records, there would be 5 buttons; 10 records, 10 buttons; etc.) Here is the subroutine I've written so far: Public Sub IsButtonVisible()
3
2163
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 kinda stuck there. but this is basicly what i want. if Username = "Deleted_User" then 'make entire table row invisible. End if
0
385
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 invisible. Only problem is when one clicks the imagebutton on a specific row, I want *only* that row's column 9 to appear or disappear. ********My imagebutton******************* <asp:TemplateColumn><ItemTemplate> <asp:ImageButton...
6
14700
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 using the Imagebutton.Attributes.Add("onMouseOver","this.src = 'somepicture.jpg') and that works fine. I've tried some java script to change the other control's visible property by changing is className, but that doesn't seem to work
3
1847
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, c0,c1,c2,c3,c4. In some case, say, case 1, I want to display columns c0, c1,c2 in dg and use c3 and c4 in code behind. In case 2, I want to display column c0, c3, and c4, and use c1 and c2 in code behind. The following Possible solution do not work:
1
1481
by: indoo | last post by:
Javascript to make a character invisible in a texbox on onfocus event. Thanks in Advance.
0
3145
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 items to the user.I don't want to remove and add items after binding the data from table I tried to find any properties{in items) to make an item invisible in combobox, but didn't find any properties to make an item invisible.Is there any...
1
2052
by: riyazuddin | last post by:
how to make a character invisible when the user is typing from keyboard in linux
0
9632
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9471
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10302
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10136
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8958
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6723
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5372
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4036
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3631
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.