473,395 Members | 1,936 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,395 software developers and data experts.

GridView /// Hiding a BoundField value

<asp:BoundField DataField="MyDate" DataFormatString="{0:d}" HeaderText="My
Date" />

I have a BoundField being populuated with the "MyDate" column.
The MyDate is in a strongly typed DataSet. The values of course come from
the DataBase.

I have a few values in the Database that have NULL as the value for MyDate.
Its not ideal, but I don't have control of this one.
Instead of passing back a NULL, I'm passing back a 12/31/1899 date value.
( This is because the Grid breaks, when I run a
DataSet.Select("somefield=123"); )

(The tsql looks like

Select
ISNULL ( MyDate , '12/31/1899') as MyDate
From
blah blah blah

I'd like to just show an emptystring or a nbsp; when I encounter dates <
1/1/1900.

Yeah, its kind of a hack, but its sufficient for this project.
Which event should I be checking?

Or is there any way to hide a the display .. based on some rule in the aspx
definition of the <asp:BoundField> ?
Thanks for any hints.

Jun 14 '06 #1
3 6110
Easy way is to add a Calculated Column to the datatable using IIF function
and use this new calculated column in the datagrid

you can use onitemdatabound event of datagrid...but needs little work.
"sloan" <sl***@ipass.net> wrote in message
news:OL**************@TK2MSFTNGP02.phx.gbl...
<asp:BoundField DataField="MyDate" DataFormatString="{0:d}" HeaderText="My
Date" />

I have a BoundField being populuated with the "MyDate" column.
The MyDate is in a strongly typed DataSet. The values of course come from
the DataBase.

I have a few values in the Database that have NULL as the value for
MyDate.
Its not ideal, but I don't have control of this one.
Instead of passing back a NULL, I'm passing back a 12/31/1899 date value.
( This is because the Grid breaks, when I run a
DataSet.Select("somefield=123"); )

(The tsql looks like

Select
ISNULL ( MyDate , '12/31/1899') as MyDate
From
blah blah blah

I'd like to just show an emptystring or a nbsp; when I encounter dates <
1/1/1900.

Yeah, its kind of a hack, but its sufficient for this project.
Which event should I be checking?

Or is there any way to hide a the display .. based on some rule in the
aspx
definition of the <asp:BoundField> ?
Thanks for any hints.

Jun 14 '06 #2
UI should not be driving your DataAccess layer.
Use the ItemCreated, ItemDataBound etc. events to modify the text or
formatting. Here are some arcticles that may help you with it.

http://www.netomatix.com/DataGridSeries.aspx
"Balasubramanian Ramanathan" <rb***********@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP04.phx.gbl...
Easy way is to add a Calculated Column to the datatable using IIF function
and use this new calculated column in the datagrid

you can use onitemdatabound event of datagrid...but needs little work.
"sloan" <sl***@ipass.net> wrote in message
news:OL**************@TK2MSFTNGP02.phx.gbl...
<asp:BoundField DataField="MyDate" DataFormatString="{0:d}"
HeaderText="My
Date" />

I have a BoundField being populuated with the "MyDate" column.
The MyDate is in a strongly typed DataSet. The values of course come
from
the DataBase.

I have a few values in the Database that have NULL as the value for
MyDate.
Its not ideal, but I don't have control of this one.
Instead of passing back a NULL, I'm passing back a 12/31/1899 date value.
( This is because the Grid breaks, when I run a
DataSet.Select("somefield=123"); )

(The tsql looks like

Select
ISNULL ( MyDate , '12/31/1899') as MyDate
From
blah blah blah

I'd like to just show an emptystring or a nbsp; when I encounter dates <
1/1/1900.

Yeah, its kind of a hack, but its sufficient for this project.
Which event should I be checking?

Or is there any way to hide a the display .. based on some rule in the
aspx
definition of the <asp:BoundField> ?
Thanks for any hints.


Jun 14 '06 #3

While I agree the UI should not be driving the DataLayer... There wasn't
much to be done when the
DataSet.Select("mycriteria"); was blowing up the databind, because of a
NULL value.
I ended up changing the <asp:BoundField> to an <asp:Label>

and putting this code in:
private void FormatLabelWithDateString(Label lbl)

{

try

{

string lblText = lbl.Text;

DateTime currentItemDate = Convert.ToDateTime(lblText);

if (currentItemDate < new DateTime(1900, 1, 1))

{

lbl.Text = "--n/a--";

}

else

{

lbl.Text = String.Format("{0:d}", currentItemDate);

}

}

catch

{ lbl.Text = "--ex--"; }

}

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)

{

if (e.Row.RowType == DataControlRowType.DataRow)

{

Label mylabel = (Label)e.Row.FindControl("lblMyDate");

if (null != mylabel)

{

FormatLabelWithDateString(mylabel);

}

}

}

I think alot of people use the DateTime.MinValue since a datetime can't be
null.
I think the 1899 thing is kinda like that.
Not perfect, but gets the job done.
Here is the aspx code to be complete:

<asp:TemplateField HeaderText="My Cool Date"
ItemStyle-HorizontalAlign="Center"

SortExpression="MyDate">

<ItemTemplate>

<asp:Label ID="lblMyDate" runat="server" Text='<%# Eval("MyDate")
%>'></asp:Label>

</ItemTemplate>

</asp:TemplateField>


"Winista" <na*********@hotmail.com> wrote in message
news:e5****************@TK2MSFTNGP04.phx.gbl...
UI should not be driving your DataAccess layer.
Use the ItemCreated, ItemDataBound etc. events to modify the text or
formatting. Here are some arcticles that may help you with it.

http://www.netomatix.com/DataGridSeries.aspx
"Balasubramanian Ramanathan" <rb***********@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP04.phx.gbl...
Easy way is to add a Calculated Column to the datatable using IIF function and use this new calculated column in the datagrid

you can use onitemdatabound event of datagrid...but needs little work.
"sloan" <sl***@ipass.net> wrote in message
news:OL**************@TK2MSFTNGP02.phx.gbl...
<asp:BoundField DataField="MyDate" DataFormatString="{0:d}"
HeaderText="My
Date" />

I have a BoundField being populuated with the "MyDate" column.
The MyDate is in a strongly typed DataSet. The values of course come
from
the DataBase.

I have a few values in the Database that have NULL as the value for
MyDate.
Its not ideal, but I don't have control of this one.
Instead of passing back a NULL, I'm passing back a 12/31/1899 date value. ( This is because the Grid breaks, when I run a
DataSet.Select("somefield=123"); )

(The tsql looks like

Select
ISNULL ( MyDate , '12/31/1899') as MyDate
From
blah blah blah

I'd like to just show an emptystring or a nbsp; when I encounter dates < 1/1/1900.

Yeah, its kind of a hack, but its sufficient for this project.
Which event should I be checking?

Or is there any way to hide a the display .. based on some rule in the
aspx
definition of the <asp:BoundField> ?
Thanks for any hints.



Jun 14 '06 #4

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

Similar topics

2
by: Michael | last post by:
Hi Everyone, I have a gridview control with the following markup: <asp:GridView ID="grdPOs" runat="server" AllowPaging="True" AutoGenerateColumns="False" BackColor="White" BorderColor="#CC9966"...
0
by: Innova | last post by:
Hi, We are working on a gridview inside the gridview (parent-child) scenario. The data of child grid will depend on the data of parent. Objectives: 1.Add new row in parent grid after each row...
2
by: Chris Davoli | last post by:
How do you enable a check box in the GridView. I selected Checkbox Field in the Columns of the GridView, and the check box shows up in the Grid view, but it is disabled. How do I enable it so I can...
1
by: DC | last post by:
The problem I'm using the .NET GridView and FormView objects for the first time and im getting the error "An OleDbParameter with ParameterName '@ID' is not contained by this...
0
by: ThePurpleCat | last post by:
Hi, I'm a newbie to ASP.NET programming but not to Visual Studio. I'm having trouble getting my Master-Details page to work. I have a page enabled GridView which is linked to a FormView control...
0
by: landesjoe | last post by:
Hi, here's my problem in short: Text boxes in gridview don't seem to hold their value if the column's .Visible property is changed back and forth. I've got a form with a gridview populated from...
2
by: Blasting Cap | last post by:
I've got a gridview (that I converted over from a datagrid, which had been working properly), that is doubling up the number of rows returned. When it was running as a datagrid, the same code sent...
4
by: =?Utf-8?B?QmFyYmFyYSBBbGRlcnRvbg==?= | last post by:
I setup a simple gridview as a utility just to do some updates, nothing fancy just wanted easy UI to make updates. When I select ‘Edit’, I get the fields I want to edit. I edit them and click...
0
by: sharonrao123 | last post by:
hello all, I have a parent gridview company and in this one a nested gridview people, Is it possible to allow the user to select one row or multiple rows from the people gridview using a check box...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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:
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...
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,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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,...

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.