Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / June 2006

Tip: Looking for answers? Try searching our database.

Suppress data from displaying in the cell in datagrid

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Antonio - 30 Jun 2006 17:01 GMT
Hello, everyone.

Is there a way to not display a certain value in a datagrid cell?

I have a datagrid for subscriptions and ebooks and if there isn't an e-book
listed, the value from the database (SQL) is "Null/No Set Dummy Row".

Is there a way I can suppress that data in the datagrid?

Thanks,

Antonio
Peter Bromberg [C# MVP] - 30 Jun 2006 17:11 GMT
Antonio,
the ItemDataBound event fires as each row of your DataGrid is bound. You can
gain access to each cell, its contents (including any controls within the
cell) in this eventhandler and make any modifications you want. See MSDN
documentation for syntax and code examples.
Peter

Signature

Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com

> Hello, everyone.
>
[quoted text clipped - 8 lines]
>
> Antonio
Antonio - 30 Jun 2006 17:44 GMT
Hi, Peter,

Thanks for replying.

I have this code in the Item_Bound method and I get a "Cannot implicitly
convert type 'string' to 'bool'

if (e.Item.Cells[4].Text = "Null/No Set Dummy Row")

e.Item.Cells[4].Text = "None";

Am I missing something?

Thank,

Antonio

> Antonio,
> the ItemDataBound event fires as each row of your DataGrid is bound. You
[quoted text clipped - 17 lines]
>>
>> Antonio
Peter Bromberg [C# MVP] - 30 Jun 2006 17:55 GMT
Antonio,
Whenever you see this exception you must remember to ask yourself,
"Should I be using one equals sign or two?".

if (e.Item.Cells[4].Text = "Null/No Set Dummy Row")

-- the above is not a test for equality. It is an attempt to ASSIGN
"Nul...." to the .Text property within an if( ... ) statement. I think you
want a test for equality
"==" here.
Peter

Signature

Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com

> Hi, Peter,
>
[quoted text clipped - 34 lines]
> >>
> >> Antonio
Antonio - 30 Jun 2006 18:05 GMT
Thank you, Peter, that gets me sometimes...

Now I am getting a
Compilation Error
Description: An error occurred during the compilation of a resource required
to service this request. Please review the following specific error details
and modify your source code appropriately.

Compiler Error Message: CS0122: 'SalesApp.subscriptions.Item_Bound(object,
System.Web.UI.WebControls.DataGridItemEventArgs)' is inaccessible due to its
protection level

and the highlighted line is line 14

Source Error:



Line 12:         <form id="Form1" method="post" runat="server">
Line 13:             <IMG style="Z-INDEX: 100; LEFT: 8px; POSITION: absolute; TOP:
8px" src="Images/logo.gif">
Line 14:             <asp:DataGrid id="dgSubs" style="Z-INDEX: 102; LEFT: 24px;
POSITION: absolute; TOP: 128px" runat="server" OnItemDataBound="Item_Bound"
Line 15:                 BorderColor="#CCCCCC" BorderStyle="Ridge" BorderWidth="1px"
BackColor="White" CellPadding="0"
Line 16:                 AllowPaging="True" Font-Size="Smaller" CellSpacing="2"
Width="1000px" HorizontalAlign="Center">


> Antonio,
> Whenever you see this exception you must remember to ask yourself,
[quoted text clipped - 46 lines]
> > >>
> > >> Antonio
Antonio - 30 Jun 2006 18:14 GMT
Ok, Peter,
I set the Item_Bound in the Page_Load event
private void Page_Load(object sender, System.EventArgs e)
{
dgSubs.ItemDataBound += new DataGridItemEventHandler(this.Item_Bound);
bindGrid();
}

The Item_Bound event is

private void Item_Bound(Object sender, DataGridItemEventArgs e)

{

if (e.Item.Cells[4].Text == "Null/No Set Dummy Row")

e.Item.Cells[4].Text = "None";

}

and it never gets to the e.Item.Cells[4].Text = "None"; line, so, it still
displays the "Null/No Set Dummy Row"

> Thank you, Peter, that gets me sometimes...
>
[quoted text clipped - 82 lines]
>> > >>
>> > >> Antonio

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.