Suppress data from displaying in the cell in datagrid

G

Guest

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
 
G

Guest

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
 
A

Antonio

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
 
G

Guest

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

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




Antonio said:
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

Peter Bromberg said:
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

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

Guest

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



Peter Bromberg said:
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

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




Antonio said:
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

Peter Bromberg said:
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

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




:

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
 
A

Antonio

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"

Antonio said:
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">



Peter Bromberg said:
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

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




Antonio said:
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

message
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

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




:

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
 

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

Top