Products

Solutions

Resources

Partners

Community

Blog

About

QA

Ideas Test

New Community Website

Ordinarily, you'd be at the right spot, but we've recently launched a brand new community website... For the community, by the community.

Yay... Take Me to the Community!

Welcome to the DNN Community Forums, your preferred source of online community support for all things related to DNN.
In order to participate you must be a registered DNNizen

HomeHomeArchived Discus...Archived Discus...Developing Under Previous Versions of .NETDeveloping Under Previous Versions of .NETASP.Net 2.0ASP.Net 2.0Null Values with ObjectDataSourceNull Values with ObjectDataSource
Previous
 
Next
New Post
12/28/2006 5:50 PM
 

I have a gridview control that is populated by an ObjectDataSource control that is hooked into my controller class. The problem I am having is getting null dates to show up as an empty string rather than 1/1/0001 12:00 AM. Ideas on how to get this to work?

<asp:TextBox ID="txtWorkOrderNo" runat="server"></asp:TextBox><asp:LinkButton ID="cmdSearchByWo"
        runat="server" CausesValidation="False" CssClass="COmmandButton">Search</asp:LinkButton></asp:Panel>

<asp:GridView ID="grdSearch" runat="server" AutoGenerateColumns="False"
    DataSourceID="ObjectDataSource1" CssClass="Mytable1" CellPadding="3">
    <Columns>
        <asp:CommandField ShowSelectButton=true  SelectText="Details" />
        <asp:BoundField DataField="WorkOrderId" HeaderText="WorkOrderId" SortExpression="WorkOrderId" />
        <asp:BoundField DataField="LocName" HeaderText="LocName" SortExpression="LocName" />
        <asp:BoundField DataField="StatusName" HeaderText="StatusName" SortExpression="StatusName" />
        
        <asp:BoundField DataField="DateOpened" DataFormatString="{0:MM/dd/yy}" HeaderText="DateOpened" ConvertEmptyStringToNull="False"
            SortExpression="DateOpened" />
        <asp:BoundField DataField="DataClosed"  DataFormatString="{0:MM/dd/yy}" HeaderText="DataClosed" SortExpression="DataClosed" ConvertEmptyStringToNull="False" />
        
    </Columns>
   <RowStyle CssClass="Normal" Wrap="False" />
                    <HeaderStyle BackColor="Black" ForeColor="White" Wrap="False" />
                    <AlternatingRowStyle BackColor="Gainsboro" />
</asp:GridView>
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server" OldValuesParameterFormatString="original_{0}"
    SelectMethod="GetWorkOrder" TypeName="FRS.FRSController">
    <SelectParameters>
        <asp:ControlParameter ControlID="txtWorkOrderNo" Name="WorkOrderId" PropertyName="Text"
            Type="Int32" />
    </SelectParameters>
</asp:ObjectDataSource> 

 
New Post
7/10/2007 12:07 PM
 

I don't think it has anything to do with your GridView config, but I may be wrong. DNN's standard Null handling is at least contributing.

I am just now looking at the same issue. It gets worse in other areas. Null doubles are returned as -1.7E308, the largest possible negative 64 bit float. Null integers are returned as -1.

I think this behaviour resides in DotNetNuke.Common.Utilities.Null.GetNull(...) in the file DotNetNuke.Library/components/shared/null.vb.

It sets my null doubles to double.minvalue which can be very interesting. The GridView renders them with all 300 zeros in a column with a {0:F} format. So, instead of a nice well behaved looking blank spot, I have a column shooting out to the right with 310 or so characters in it. Unfortunately, I have several of these columns side by side and all the sudden my grid is rendered with several thousand characters across!. It's exciting and a new UI design statement.

DNN or DNN and DAAB are aparently "coding" the nulls instead of handling them as null or nothing when you use the GetNull method. I've coded for DNN for years, but never had needed to deal with this. My data has nulls that need to stay nulls, so I will have to trace through this and find a solution that works. I really don't want to change any of the base DNN files and would like to handle this externally in my custom module while using DAL code that is as close to standard as possible.

 

 
New Post
7/10/2007 3:53 PM
 

Ok, I see where this happens. It is in FillCollection(..) , FillObject(..), CreateObject(..) used when DAL creates the collection that gets bound to the GridView in DotNetNuke.Common.Utilities.CBO. I don't see a way to turn off the behavior. Nulls are simply coded this way. There is a GetNull function available to reverse the conversion, but FillCollection does not use it. Users of the collectiion are expected to, I guess.

The fact that -1 is used for the Null integer value may be the show stopper for me. I can't affort to look at an integer and assume that a value -1 means it used to be a Null. -1 is a valid value for some columns.. I wonder why the decision was to use -1 instead of integer.MinValue like the other null conversions.

The only options I see for now are 1) translate my doubles to varchars somehow using a view before I bring them in to the module. This way nulls would translate to empty string instead of "- mass of the universe". 2) alter the DNN framework classes (nahh...) 3) Use direct DB calls and avoid DAL in my module.. None are good choices.

 

 
New Post
7/10/2007 4:51 PM
 

The use of FillObject and FillCollection is now discouraged by the CT for performance reasons. I believe Charles Nurse recommended in one of his posts to use your own helper functions to fill the objects in your application, instead of those two methods. By using this approach you are still using the DAL to connect to the DB most often returning a Datareader to your controller and then filling an info object with the returned values.

For example for a Datareader called dr:

Private Function FillMyObjectInfo(ByVal dr As IDataReader, ByVal CheckForOpenDatareader As Boolean, ByVal IncludePermissions As Boolean) As MyObjectInfo

Dim intObject_ID As Integer = Convert.ToInt32(Null.SetNull(dr("EntidadFinanciera_ID"), intObject_ID))

Dim strObjectName As String = Convert.ToString(Null.SetNull(dr("EntidadName"), strObjectName))

Dim oObjectInfo As New ObjectInfo(intObject_ID, strObjectName )

End Function

The Null.SetNull method comes from the mentioned Null Class in the Dotnetnuke.Common.Utilities namespace. By checking for the value instead of using the method with your own, I believe it would be possible to handle nulls in the way you want to.


Do you know the truth when you hear it?
Néstor Sánchez
The Dúnadan Raptor -->Follow Me on Twitter Now!
 
New Post
7/10/2007 5:17 PM
 

Thanks,

I was being quite lazy, but the more experimentation I do, the more I realize that I have to do this myself and not use the CBO classes. It may also be difficult to use GridView and ObjectDataSource as they don't give enough low level control of the rendering. Maybe not. I'm still looking.

Thanks for getting me back on track. I actually had seen those posts and went back to re-read them. Here they are for reference.

http://www.dotnetnuke.com/Default.aspx?tabid=825&EntryID=1116

http://www.dotnetnuke.com/Community/Blogs/tabid/825/EntryID/1221/Default.aspx

 
Previous
 
Next
HomeHomeArchived Discus...Archived Discus...Developing Under Previous Versions of .NETDeveloping Under Previous Versions of .NETASP.Net 2.0ASP.Net 2.0Null Values with ObjectDataSourceNull Values with ObjectDataSource


These Forums are dedicated to discussion of DNN Platform and Evoq Solutions.

For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

  1. No Advertising. This includes promotion of commercial and non-commercial products or services which are not directly related to DNN.
  2. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
  3. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  4. No Flaming or Trolling.
  5. No Profanity, Racism, or Prejudice.
  6. Site Moderators have the final word on approving / removing a thread or post or comment.
  7. English language posting only, please.
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out