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

DataBinder.Eval(Container.DataItem, "date") when date might be missing

bg
Hi!

How do I check if "date" exists before using that code?

I've built a RSSreader and sometimes there's a date in it and sometimes not.
How can I check if it exists to avoid crash (DataBinder.Eval:
'System.Data.DataRowView' does not contain a property with the name date)

<asp:DataGrid
id="RssNewsGrid"
AutoGenerateColumns="False"
runat="server"
AlternatingItemStyle-BackColor="#ffffff"
HeaderStyle-BackColor="#ffffff"
OnPageIndexChanged="ChangePaging"
AllowPaging="True"
Width="100%"
Cellpadding="4"
BorderWidth="0">
<PagerStyle Mode="NumericPages" Visible="False" HorizontalAlign="Right" />
<Columns>
<asp:TemplateColumn>
<HeaderTemplate>
</HeaderTemplate>
<ItemTemplate>
<h2 class="<%=HeaderClass2%>"><%# DataBinder.Eval(Container.DataItem,
"title") %></h2>
<em><%# DataBinder.Eval(Container.DataItem, "date") %>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:DataGrid>
Thank you
/Stefan

Nov 18 '05 #1
6 6423
One solution is to call a method in your page object intead of
DataBinder.Eval, i.e.:

<%# GetDate(Container.DataItem %>

Them implement GetDate to look for the optional field and return
String.Empty if not present.

--
Scott
http://www.OdeToCode.com
On Wed, 14 Apr 2004 18:19:20 +0200, "bg"
<st**************@hotmail.com> wrote:
Hi!

How do I check if "date" exists before using that code?

I've built a RSSreader and sometimes there's a date in it and sometimes not.
How can I check if it exists to avoid crash (DataBinder.Eval:
'System.Data.DataRowView' does not contain a property with the name date)

<asp:DataGrid
id="RssNewsGrid"
AutoGenerateColumns="False"
runat="server"
AlternatingItemStyle-BackColor="#ffffff"
HeaderStyle-BackColor="#ffffff"
OnPageIndexChanged="ChangePaging"
AllowPaging="True"
Width="100%"
Cellpadding="4"
BorderWidth="0">
<PagerStyle Mode="NumericPages" Visible="False" HorizontalAlign="Right" />
<Columns>
<asp:TemplateColumn>
<HeaderTemplate>
</HeaderTemplate>
<ItemTemplate>
<h2 class="<%=HeaderClass2%>"><%# DataBinder.Eval(Container.DataItem,
"title") %></h2>
<em><%# DataBinder.Eval(Container.DataItem, "date") %>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:DataGrid>
Thank you
/Stefan


Nov 18 '05 #2
bg
Hi Scott and thanks for the tip.

I tried that yesterday but don't know what type to declare. DataItem seems
not to exists... String wont work of couse.
public string GetDate2(string sIn)
{

Thanks
/Stefan
"Scott Allen" <bitmask@[nospam].fred.net> wrote in message
news:ss********************************@4ax.com...
One solution is to call a method in your page object intead of
DataBinder.Eval, i.e.:

<%# GetDate(Container.DataItem %>

Them implement GetDate to look for the optional field and return
String.Empty if not present.

--
Scott
http://www.OdeToCode.com
On Wed, 14 Apr 2004 18:19:20 +0200, "bg"
<st**************@hotmail.com> wrote:
Hi!

How do I check if "date" exists before using that code?

I've built a RSSreader and sometimes there's a date in it and sometimes not.How can I check if it exists to avoid crash (DataBinder.Eval:
'System.Data.DataRowView' does not contain a property with the name date)

<asp:DataGrid
id="RssNewsGrid"
AutoGenerateColumns="False"
runat="server"
AlternatingItemStyle-BackColor="#ffffff"
HeaderStyle-BackColor="#ffffff"
OnPageIndexChanged="ChangePaging"
AllowPaging="True"
Width="100%"
Cellpadding="4"
BorderWidth="0">
<PagerStyle Mode="NumericPages" Visible="False" HorizontalAlign="Right" /> <Columns>
<asp:TemplateColumn>
<HeaderTemplate>
</HeaderTemplate>
<ItemTemplate>
<h2 class="<%=HeaderClass2%>"><%# DataBinder.Eval(Container.DataItem,
"title") %></h2>
<em><%# DataBinder.Eval(Container.DataItem, "date") %>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:DataGrid>
Thank you
/Stefan

Nov 18 '05 #3
bg
Hi Scott and thanks for the tip.

I tried that yesterday but don't know what type to declare. DataItem seems
not to exists... String wont work of couse.
public string GetDate2(string sIn)
{

Thanks
/Stefan
"Scott Allen" <bitmask@[nospam].fred.net> wrote in message
news:ss********************************@4ax.com...
One solution is to call a method in your page object intead of
DataBinder.Eval, i.e.:

<%# GetDate(Container.DataItem %>

Them implement GetDate to look for the optional field and return
String.Empty if not present.

--
Scott
http://www.OdeToCode.com
On Wed, 14 Apr 2004 18:19:20 +0200, "bg"
<st**************@hotmail.com> wrote:
Hi!

How do I check if "date" exists before using that code?

I've built a RSSreader and sometimes there's a date in it and sometimes not.How can I check if it exists to avoid crash (DataBinder.Eval:
'System.Data.DataRowView' does not contain a property with the name date)

<asp:DataGrid
id="RssNewsGrid"
AutoGenerateColumns="False"
runat="server"
AlternatingItemStyle-BackColor="#ffffff"
HeaderStyle-BackColor="#ffffff"
OnPageIndexChanged="ChangePaging"
AllowPaging="True"
Width="100%"
Cellpadding="4"
BorderWidth="0">
<PagerStyle Mode="NumericPages" Visible="False" HorizontalAlign="Right" /> <Columns>
<asp:TemplateColumn>
<HeaderTemplate>
</HeaderTemplate>
<ItemTemplate>
<h2 class="<%=HeaderClass2%>"><%# DataBinder.Eval(Container.DataItem,
"title") %></h2>
<em><%# DataBinder.Eval(Container.DataItem, "date") %>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:DataGrid>
Thank you
/Stefan

Nov 18 '05 #4
Well, it depends on what the DataSource is (an XmlDocument, an
ArrayList, a DataSet, etc).

Something you could try is:

public string GetDate(object o)
{
return String.Empty;
}

and set a breakpoint on the method. Then when you run with the
debugger you can inspect o in a quick watch window and see what type
the data binding is passing. Then go back and declare the method with
the correct type and work from there. A bit of a hack, but like I say,
depending on your DataSource you'll get different types of object
references here.

HTH,
--
Scott
http://www.OdeToCode.com

On Thu, 15 Apr 2004 10:36:43 +0200, "bg"
<st**************@hotmail.com> wrote:
Hi Scott and thanks for the tip.

I tried that yesterday but don't know what type to declare. DataItem seems
not to exists... String wont work of couse.
public string GetDate2(string sIn)
{

Thanks
/Stefan
"Scott Allen" <bitmask@[nospam].fred.net> wrote in message
news:ss********************************@4ax.com.. .
One solution is to call a method in your page object intead of
DataBinder.Eval, i.e.:

<%# GetDate(Container.DataItem %>

Them implement GetDate to look for the optional field and return
String.Empty if not present.

--
Scott
http://www.OdeToCode.com
On Wed, 14 Apr 2004 18:19:20 +0200, "bg"
<st**************@hotmail.com> wrote:
>Hi!
>
>How do I check if "date" exists before using that code?
>
>I've built a RSSreader and sometimes there's a date in it and sometimesnot. >How can I check if it exists to avoid crash (DataBinder.Eval:
>'System.Data.DataRowView' does not contain a property with the name date)
>
><asp:DataGrid
> id="RssNewsGrid"
> AutoGenerateColumns="False"
> runat="server"
> AlternatingItemStyle-BackColor="#ffffff"
> HeaderStyle-BackColor="#ffffff"
> OnPageIndexChanged="ChangePaging"
> AllowPaging="True"
> Width="100%"
> Cellpadding="4"
> BorderWidth="0">
> <PagerStyle Mode="NumericPages" Visible="False" HorizontalAlign="Right"/> > <Columns>
> <asp:TemplateColumn>
> <HeaderTemplate>
> </HeaderTemplate>
> <ItemTemplate>
> <h2 class="<%=HeaderClass2%>"><%# DataBinder.Eval(Container.DataItem,
>"title") %></h2>
> <em><%# DataBinder.Eval(Container.DataItem, "date") %>
> </ItemTemplate>
> </asp:TemplateColumn>
> </Columns>
></asp:DataGrid>
>
>
>Thank you
>/Stefan
>
>


Nov 18 '05 #5
bg
Hi Scott!

I finally made it after a lot of try and error. Thanks for all the help. I
had problems understanding the object model any ideas where I can learn more
so I get this (including my own code :-> )?
/Stefan

The result:
public string GetDate(Object o)
{
string ret = "";

DataRowView drv = (DataRowView) o;

if (drv.Row.Table.Columns.Contains("date"))
{
int index = drv.Row.Table.Columns.IndexOf("date");
ret = drv.Row.ItemArray.GetValue(index).ToString().Subst ring(0, 10);
}

return ret;
}
<asp:DataGrid
id="RssNewsGrid"
AutoGenerateColumns="False"
runat="server"
AlternatingItemStyle-BackColor="#ffffff"
HeaderStyle-BackColor="#ffffff"
OnPageIndexChanged="ChangePaging"
AllowPaging="True"
Width="100%"
Cellpadding="4"
BorderWidth="0">
<PagerStyle Mode="NumericPages" Visible="False" HorizontalAlign="Right" />
<Columns>
<asp:TemplateColumn>
<HeaderTemplate>
</HeaderTemplate>
<ItemTemplate>
<h2 class="<%=HeaderClass2%>"><%# DataBinder.Eval(Container.DataItem,
"title") %></h2>
<em><asp:Label CssClass="txtNormal" runat="server" Text='<%#
GetDate(Container.DataItem) %>' ' ID="Label2" NAME="Label2"/></em>
<asp:Label CssClass="txtNormal" runat="server"
Text='<%#DataBinder.Eval(Container.DataItem, "description") %>' ID="Label1"
NAME="Label1"/>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:DataGrid>
Thanks again


"Scott Allen" <bitmask@[nospam].fred.net> wrote in message
news:3l********************************@4ax.com...
Well, it depends on what the DataSource is (an XmlDocument, an
ArrayList, a DataSet, etc).

Something you could try is:

public string GetDate(object o)
{
return String.Empty;
}

and set a breakpoint on the method. Then when you run with the
debugger you can inspect o in a quick watch window and see what type
the data binding is passing. Then go back and declare the method with
the correct type and work from there. A bit of a hack, but like I say,
depending on your DataSource you'll get different types of object
references here.

HTH,
--
Scott
http://www.OdeToCode.com

On Thu, 15 Apr 2004 10:36:43 +0200, "bg"
<st**************@hotmail.com> wrote:
Hi Scott and thanks for the tip.

I tried that yesterday but don't know what type to declare. DataItem seemsnot to exists... String wont work of couse.
public string GetDate2(string sIn)
{

Thanks
/Stefan
"Scott Allen" <bitmask@[nospam].fred.net> wrote in message
news:ss********************************@4ax.com.. .
One solution is to call a method in your page object intead of
DataBinder.Eval, i.e.:

<%# GetDate(Container.DataItem %>

Them implement GetDate to look for the optional field and return
String.Empty if not present.

--
Scott
http://www.OdeToCode.com
On Wed, 14 Apr 2004 18:19:20 +0200, "bg"
<st**************@hotmail.com> wrote:

>Hi!
>
>How do I check if "date" exists before using that code?
>
>I've built a RSSreader and sometimes there's a date in it and sometimes
not.
>How can I check if it exists to avoid crash (DataBinder.Eval:
>'System.Data.DataRowView' does not contain a property with the name
date) >
><asp:DataGrid
> id="RssNewsGrid"
> AutoGenerateColumns="False"
> runat="server"
> AlternatingItemStyle-BackColor="#ffffff"
> HeaderStyle-BackColor="#ffffff"
> OnPageIndexChanged="ChangePaging"
> AllowPaging="True"
> Width="100%"
> Cellpadding="4"
> BorderWidth="0">
> <PagerStyle Mode="NumericPages" Visible="False" HorizontalAlign="Right"/>
> <Columns>
> <asp:TemplateColumn>
> <HeaderTemplate>
> </HeaderTemplate>
> <ItemTemplate>
> <h2 class="<%=HeaderClass2%>"><%#

DataBinder.Eval(Container.DataItem, >"title") %></h2>
> <em><%# DataBinder.Eval(Container.DataItem, "date") %>
> </ItemTemplate>
> </asp:TemplateColumn>
> </Columns>
></asp:DataGrid>
>
>
>Thank you
>/Stefan
>
>

Nov 18 '05 #6
I'm glad you have everything working.

Try search for:
dino esposito data binding

Dino has written a number of good articles on various places around
the web.

--
Scott
http://www.OdeToCode.com

On Fri, 16 Apr 2004 13:43:27 +0200, "bg"
<st**************@hotmail.com> wrote:
Hi Scott!

I finally made it after a lot of try and error. Thanks for all the help. I
had problems understanding the object model any ideas where I can learn more
so I get this (including my own code :-> )?
/Stefan

The result:
public string GetDate(Object o)
{
string ret = "";

DataRowView drv = (DataRowView) o;

if (drv.Row.Table.Columns.Contains("date"))
{
int index = drv.Row.Table.Columns.IndexOf("date");
ret = drv.Row.ItemArray.GetValue(index).ToString().Subst ring(0, 10);
}

return ret;
}
<asp:DataGrid
id="RssNewsGrid"
AutoGenerateColumns="False"
runat="server"
AlternatingItemStyle-BackColor="#ffffff"
HeaderStyle-BackColor="#ffffff"
OnPageIndexChanged="ChangePaging"
AllowPaging="True"
Width="100%"
Cellpadding="4"
BorderWidth="0">
<PagerStyle Mode="NumericPages" Visible="False" HorizontalAlign="Right" />
<Columns>
<asp:TemplateColumn>
<HeaderTemplate>
</HeaderTemplate>
<ItemTemplate>
<h2 class="<%=HeaderClass2%>"><%# DataBinder.Eval(Container.DataItem,
"title") %></h2>
<em><asp:Label CssClass="txtNormal" runat="server" Text='<%#
GetDate(Container.DataItem) %>' ' ID="Label2" NAME="Label2"/></em>
<asp:Label CssClass="txtNormal" runat="server"
Text='<%#DataBinder.Eval(Container.DataItem, "description") %>' ID="Label1"
NAME="Label1"/>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:DataGrid>
Thanks again


"Scott Allen" <bitmask@[nospam].fred.net> wrote in message
news:3l********************************@4ax.com.. .
Well, it depends on what the DataSource is (an XmlDocument, an
ArrayList, a DataSet, etc).

Something you could try is:

public string GetDate(object o)
{
return String.Empty;
}

and set a breakpoint on the method. Then when you run with the
debugger you can inspect o in a quick watch window and see what type
the data binding is passing. Then go back and declare the method with
the correct type and work from there. A bit of a hack, but like I say,
depending on your DataSource you'll get different types of object
references here.

HTH,
--
Scott
http://www.OdeToCode.com

On Thu, 15 Apr 2004 10:36:43 +0200, "bg"
<st**************@hotmail.com> wrote:
>Hi Scott and thanks for the tip.
>
>I tried that yesterday but don't know what type to declare. DataItemseems >not to exists... String wont work of couse.
> public string GetDate2(string sIn)
> {
>
>Thanks
>/Stefan
>
>
>"Scott Allen" <bitmask@[nospam].fred.net> wrote in message
>news:ss********************************@4ax.com.. .
>> One solution is to call a method in your page object intead of
>> DataBinder.Eval, i.e.:
>>
>> <%# GetDate(Container.DataItem %>
>>
>> Them implement GetDate to look for the optional field and return
>> String.Empty if not present.
>>
>> --
>> Scott
>> http://www.OdeToCode.com
>>
>>
>> On Wed, 14 Apr 2004 18:19:20 +0200, "bg"
>> <st**************@hotmail.com> wrote:
>>
>> >Hi!
>> >
>> >How do I check if "date" exists before using that code?
>> >
>> >I've built a RSSreader and sometimes there's a date in it andsometimes >not.
>> >How can I check if it exists to avoid crash (DataBinder.Eval:
>> >'System.Data.DataRowView' does not contain a property with the namedate) >> >
>> ><asp:DataGrid
>> > id="RssNewsGrid"
>> > AutoGenerateColumns="False"
>> > runat="server"
>> > AlternatingItemStyle-BackColor="#ffffff"
>> > HeaderStyle-BackColor="#ffffff"
>> > OnPageIndexChanged="ChangePaging"
>> > AllowPaging="True"
>> > Width="100%"
>> > Cellpadding="4"
>> > BorderWidth="0">
>> > <PagerStyle Mode="NumericPages" Visible="False"HorizontalAlign="Right" >/>
>> > <Columns>
>> > <asp:TemplateColumn>
>> > <HeaderTemplate>
>> > </HeaderTemplate>
>> > <ItemTemplate>
>> > <h2 class="<%=HeaderClass2%>"><%#DataBinder.Eval(Container.DataItem, >> >"title") %></h2>
>> > <em><%# DataBinder.Eval(Container.DataItem, "date") %>
>> > </ItemTemplate>
>> > </asp:TemplateColumn>
>> > </Columns>
>> ></asp:DataGrid>
>> >
>> >
>> >Thank you
>> >/Stefan
>> >
>> >
>>
>


Nov 18 '05 #7

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

Similar topics

0
by: Michelle Keys | last post by:
Subject: DataBinder.Eval Error! Server Error in '/MSPOS' Application. ------------------------------------------------------------------------ -------- DataBinder.Eval:...
1
by: Andy Crawford | last post by:
Even though I have set Strict Off, it is still on, thus causing this error. Here is the code in a templated Column of a DataGrid: (XPpro, Framework 1.1) <ItemTemplate> <TABLE width="100%">...
5
by: bg | last post by:
Hi! How do I check if "date" exists before using that code? I've built a RSSreader and sometimes there's a date in it and sometimes not. How can I check if it exists to avoid crash...
1
by: Charlie | last post by:
Hi: Is it possible to apply formatting to above statements which insert field values into HTML when binding to a datasource using Repeater control? For example, I would like to trim trailing...
4
by: Søren Lund | last post by:
Hello, I am trying to bind a DataGrid with some data from a DataSet which contains fields in the form "group.fieldname". I am certain that my data source contains the field but I cannot get my...
1
by: Mike Lerch | last post by:
Pretty much, TSIA, but I'll expand a bit: I'm still trying to get my head around the n-tier approach to web design. It seems to me that when you use DataBinder.Eval in the ASPX that your tiers...
1
by: Nathan Sokalski | last post by:
I want to make an email link using databinding. I am able to get and display the email address from the database it is stored in using databinding as follows: <asp:HyperLink id="lnkEmail1"...
3
by: Mark Jones | last post by:
I am quite new to ASP and .Net development and I am building a web-based multiple choice exam application. The web page displays the questions using a Repeater control and the answers are nested...
1
by: RobASPNewGuy | last post by:
Hi, I'm new to this forum and hope I can get some help. I would like to make life easier by combining a appSetting (global variable set in the web.config file) and DataBinder.Eval to create a...
6
by: rn5a | last post by:
What's the difference between <%# DataBinder.Eval(Container.DataItem,"LastName") %> & <%# Container.DataItem("LastName") %> Thanks
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
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
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...
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
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.