473,545 Members | 2,095 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

GridView /// Hiding a BoundField value

<asp:BoundFie ld DataField="MyDa te" DataFormatStrin g="{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 6123
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.ne t> wrote in message
news:OL******** ******@TK2MSFTN GP02.phx.gbl...
<asp:BoundFie ld DataField="MyDa te" DataFormatStrin g="{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
"Balasubramania n Ramanathan" <rb***********@ hotmail.com> wrote in message
news:%2******** ********@TK2MSF TNGP04.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.ne t> wrote in message
news:OL******** ******@TK2MSFTN GP02.phx.gbl...
<asp:BoundFie ld DataField="MyDa te" DataFormatStrin g="{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 FormatLabelWith DateString(Labe l lbl)

{

try

{

string lblText = lbl.Text;

DateTime currentItemDate = Convert.ToDateT ime(lblText);

if (currentItemDat e < new DateTime(1900, 1, 1))

{

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

}

else

{

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

}

}

catch

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

}

protected void GridView1_RowDa taBound(object sender, GridViewRowEven tArgs e)

{

if (e.Row.RowType == DataControlRowT ype.DataRow)

{

Label mylabel = (Label)e.Row.Fi ndControl("lblM yDate");

if (null != mylabel)

{

FormatLabelWith DateString(myla bel);

}

}

}

I think alot of people use the DateTime.MinVal ue 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:TemplateFi eld HeaderText="My Cool Date"
ItemStyle-HorizontalAlign ="Center"

SortExpression= "MyDate">

<ItemTemplate >

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

</ItemTemplate>

</asp:TemplateFie ld>


"Winista" <na*********@ho tmail.com> wrote in message
news:e5******** ********@TK2MSF TNGP04.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
"Balasubramania n Ramanathan" <rb***********@ hotmail.com> wrote in message
news:%2******** ********@TK2MSF TNGP04.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.ne t> wrote in message
news:OL******** ******@TK2MSFTN GP02.phx.gbl...
<asp:BoundFie ld DataField="MyDa te" DataFormatStrin g="{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
2787
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" BorderStyle="None" BorderWidth="1px" CellPadding="4" DataKeyNames="ItemId" Height="68px" PageSize="5" Width="642px"> <FooterStyle...
0
8555
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 and add child grid into that row because the columns in child grid are same as parent grid and we want to align them with the cols of parent grid....
2
3582
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 check/uncheck it. Also, what event do I use to check it for a value? Any articles out there? -- Chris Davoli
1
541
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 OleDbParameterCollection" whenI try to write a new record. Delete and Modify work fine its just the add record function causes the error.
0
4737
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 through an objectdatasource. The paging on my GridView works fine except that when I change the page the FormView does not update. I tried setting...
0
2408
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 a data view (which in turn is loaded from a manually setup DataTable for testing purposes). One of the columns in the grid is a checkbox that's...
2
2099
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 back the proper number of rows. The only thing different I am doing is to display the number of rows returned in the footer of the gridview. The...
4
8739
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 ‘Update’, the page returns to its original state (prior to clicking Edit) and no updates occur in the DB. What am I missing? I included the...
0
4642
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 and also get the datakey (in my case personid) of the the rows selected. Please point me in the right direction. This is what i have so far but i...
0
7464
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...
0
7656
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. ...
0
7805
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...
1
7413
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
4943
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...
0
3449
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...
0
3440
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1874
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
0
700
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.