By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,278 Members | 1,135 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,278 IT Pros & Developers. It's quick & easy.

How to format databound by DataList Control ?

P: n/a
Hi,

I have a problem of displaying data bound by a datalist control. In my
table, I have a field Start_date which has Short Date data type. I tried to
update this field by Current Date. After that, I display End_Date on the
DataList control. The output looks like 3/18/2005 12:00:00 AM . I'd
like to format data for this field to be 3/18/2005. Please help me.

Thanks in advance.
================================================== ===================
My DataList Control with the declaration as following:

<asp:DataList id="myDataList" OnItemDataBound="DataList_ItemBound"
Runat="Server" Width="500">
<HeaderTemplate>
<table border= "0">
</HeaderTemplate>
<ItemTemplate>
<tr>
<td class="dataTD" width= "100" >
<b>Start Date:</b>&nbsp;&nbsp;</b>
</td>
<td class="dataTD" width= "400">
<%# Container.DataItem("Start_Date") %>
</td>
</tr>
</ItemTemplate>
<SeparatorTemplate>
<tr>
<td colspan= "2" width= "500" align= "center">
<hr />
</td>
</tr>
</SeparatorTemplate>
<FooterTemplate>
<div align="center">
<tr>
<td colspan= "2" width= "500" align= "center">

</td>
</tr>
</table>
</FooterTemplate>
</asp:DataList>
Nov 19 '05 #1
Share this Question
Share on Google+
8 Replies


P: n/a
It seems like a custom date format string should handle that. You can insert
the function right in your HTML code as shown below.

Is that what you needed?

Ken
Microsoft MVP [ASP.NET]
Toronto

<form id="Form1" method="post" runat="server">
<asp:datalist id="myDataList"
OnItemDataBound="DataList_ItemBound" Runat="Server" Width="500">
<headertemplate>
<table border="0">
</headertemplate>
<itemtemplate>
<tr>
<td class="dataTD" width="100">
<b>Start Date:</b>&nbsp;&nbsp;</b>
</td>
<td class="dataTD" width="400">
<%#Format(Container.DataItem("Start_Date"),
"d/M/yyyy") %>
</td>
</tr>
</itemtemplate>
<separatortemplate>
<tr>
<td colspan="2" width="500" align="center">
<hr />
</td>
</tr>
</separatortemplate>
<footertemplate>
<div align="center">
<tr>
<td colspan="2" width="500" align="center">
</td>
</tr>
</table>
</footertemplate>
</asp:datalist>
</form>

Private Sub Page_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
If Not IsPostBack Then
myDataList.DataSource = CreateDataSource()
myDataList.DataBind()
End If
End Sub

Public Sub DataList_ItemBound(ByVal sender As Object, _
ByVal e As System.Web.UI.WebControls.DataListItemEventArgs)
End Sub
Function CreateDataSource() As DataTable
Dim dt As New DataTable
Dim dr As DataRow
dt.Columns.Add(New DataColumn _
("Start_Date", GetType(DateTime)))
Dim i As Integer
For i = 0 To 4
dr = dt.NewRow()
dr(0) = Now.AddDays(i)
dt.Rows.Add(dr)
Next i
Return dt
End Function 'CreateDataSource
"bienwell" <bi******@hotmail.com> wrote in message
news:ec**************@TK2MSFTNGP10.phx.gbl...
Hi,

I have a problem of displaying data bound by a datalist control. In my
table, I have a field Start_date which has Short Date data type. I tried
to
update this field by Current Date. After that, I display End_Date on the
DataList control. The output looks like 3/18/2005 12:00:00 AM . I'd
like to format data for this field to be 3/18/2005. Please help me.

Thanks in advance.
================================================== ===================
My DataList Control with the declaration as following:

<asp:DataList id="myDataList" OnItemDataBound="DataList_ItemBound"
Runat="Server" Width="500">
<HeaderTemplate>
<table border= "0">
</HeaderTemplate>
<ItemTemplate>
<tr>
<td class="dataTD" width= "100" >
<b>Start Date:</b>&nbsp;&nbsp;</b>
</td>
<td class="dataTD" width= "400">
<%# Container.DataItem("Start_Date") %>
</td>
</tr>
</ItemTemplate>
<SeparatorTemplate>
<tr>
<td colspan= "2" width= "500" align= "center">
<hr />
</td>
</tr>
</SeparatorTemplate>
<FooterTemplate>
<div align="center">
<tr>
<td colspan= "2" width= "500" align= "center">

</td>
</tr>
</table>
</FooterTemplate>
</asp:DataList>


Nov 19 '05 #2

P: n/a
Ken,

It's exactly what I need. However, when I tried it, I've got this error :

Argument 'Expression' is not a valid value.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

Exception Details: System.ArgumentException: Argument 'Expression' is not a
valid value.

Source Error:

Line 264: </td>
Line 265: <td class="dataTD" width= "400">
Line 266: <%#Format(Container.DataItem("Start_Date"),
"d/M/yyyy") %>


================================================== ==========================
=========
"Ken Cox [Microsoft MVP]" <BA************@sympatico.ca> wrote in message
news:u9**************@TK2MSFTNGP12.phx.gbl...
It seems like a custom date format string should handle that. You can insert the function right in your HTML code as shown below.

Is that what you needed?

Ken
Microsoft MVP [ASP.NET]
Toronto

<form id="Form1" method="post" runat="server">
<asp:datalist id="myDataList"
OnItemDataBound="DataList_ItemBound" Runat="Server" Width="500">
<headertemplate>
<table border="0">
</headertemplate>
<itemtemplate>
<tr>
<td class="dataTD" width="100">
<b>Start Date:</b>&nbsp;&nbsp;</b>
</td>
<td class="dataTD" width="400">
<%#Format(Container.DataItem("Start_Date"),
"d/M/yyyy") %>
</td>
</tr>
</itemtemplate>
<separatortemplate>
<tr>
<td colspan="2" width="500" align="center">
<hr />
</td>
</tr>
</separatortemplate>
<footertemplate>
<div align="center">
<tr>
<td colspan="2" width="500" align="center">
</td>
</tr>
</table>
</footertemplate>
</asp:datalist>
</form>

Private Sub Page_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
If Not IsPostBack Then
myDataList.DataSource = CreateDataSource()
myDataList.DataBind()
End If
End Sub

Public Sub DataList_ItemBound(ByVal sender As Object, _
ByVal e As System.Web.UI.WebControls.DataListItemEventArgs)
End Sub
Function CreateDataSource() As DataTable
Dim dt As New DataTable
Dim dr As DataRow
dt.Columns.Add(New DataColumn _
("Start_Date", GetType(DateTime)))
Dim i As Integer
For i = 0 To 4
dr = dt.NewRow()
dr(0) = Now.AddDays(i)
dt.Rows.Add(dr)
Next i
Return dt
End Function 'CreateDataSource
"bienwell" <bi******@hotmail.com> wrote in message
news:ec**************@TK2MSFTNGP10.phx.gbl...
Hi,

I have a problem of displaying data bound by a datalist control. In my
table, I have a field Start_date which has Short Date data type. I tried to
update this field by Current Date. After that, I display End_Date on the
DataList control. The output looks like 3/18/2005 12:00:00 AM . I'd
like to format data for this field to be 3/18/2005. Please help me.

Thanks in advance.
================================================== ===================
My DataList Control with the declaration as following:

<asp:DataList id="myDataList" OnItemDataBound="DataList_ItemBound"
Runat="Server" Width="500">
<HeaderTemplate>
<table border= "0">
</HeaderTemplate>
<ItemTemplate>
<tr>
<td class="dataTD" width= "100" >
<b>Start Date:</b>&nbsp;&nbsp;</b>
</td>
<td class="dataTD" width= "400">
<%# Container.DataItem("Start_Date") %>
</td>
</tr>
</ItemTemplate>
<SeparatorTemplate>
<tr>
<td colspan= "2" width= "500" align= "center">
<hr />
</td>
</tr>
</SeparatorTemplate>
<FooterTemplate>
<div align="center">
<tr>
<td colspan= "2" width= "500" align= "center">

</td>
</tr>
</table>
</FooterTemplate>
</asp:DataList>

Nov 19 '05 #3

P: n/a
Ken,

It's exactly what I need. I've got this error message when I tried it:

Argument 'Expression' is not a valid value.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

Exception Details: System.ArgumentException: Argument 'Expression' is not a
valid value.

Source Error:

Line 264: </td>
Line 265: <td class="dataTD" width= "400">
Line 266: <%#Format(Container.DataItem("Start_Date"),
"d/M/yyyy") %>

================================================== ============

"Ken Cox [Microsoft MVP]" <BA************@sympatico.ca> wrote in message
news:u9**************@TK2MSFTNGP12.phx.gbl...
It seems like a custom date format string should handle that. You can insert the function right in your HTML code as shown below.

Is that what you needed?

Ken
Microsoft MVP [ASP.NET]
Toronto

<form id="Form1" method="post" runat="server">
<asp:datalist id="myDataList"
OnItemDataBound="DataList_ItemBound" Runat="Server" Width="500">
<headertemplate>
<table border="0">
</headertemplate>
<itemtemplate>
<tr>
<td class="dataTD" width="100">
<b>Start Date:</b>&nbsp;&nbsp;</b>
</td>
<td class="dataTD" width="400">
<%#Format(Container.DataItem("Start_Date"),
"d/M/yyyy") %>
</td>
</tr>
</itemtemplate>
<separatortemplate>
<tr>
<td colspan="2" width="500" align="center">
<hr />
</td>
</tr>
</separatortemplate>
<footertemplate>
<div align="center">
<tr>
<td colspan="2" width="500" align="center">
</td>
</tr>
</table>
</footertemplate>
</asp:datalist>
</form>

Private Sub Page_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
If Not IsPostBack Then
myDataList.DataSource = CreateDataSource()
myDataList.DataBind()
End If
End Sub

Public Sub DataList_ItemBound(ByVal sender As Object, _
ByVal e As System.Web.UI.WebControls.DataListItemEventArgs)
End Sub
Function CreateDataSource() As DataTable
Dim dt As New DataTable
Dim dr As DataRow
dt.Columns.Add(New DataColumn _
("Start_Date", GetType(DateTime)))
Dim i As Integer
For i = 0 To 4
dr = dt.NewRow()
dr(0) = Now.AddDays(i)
dt.Rows.Add(dr)
Next i
Return dt
End Function 'CreateDataSource
"bienwell" <bi******@hotmail.com> wrote in message
news:ec**************@TK2MSFTNGP10.phx.gbl...
Hi,

I have a problem of displaying data bound by a datalist control. In my
table, I have a field Start_date which has Short Date data type. I tried to
update this field by Current Date. After that, I display End_Date on the
DataList control. The output looks like 3/18/2005 12:00:00 AM . I'd
like to format data for this field to be 3/18/2005. Please help me.

Thanks in advance.
================================================== ===================
My DataList Control with the declaration as following:

<asp:DataList id="myDataList" OnItemDataBound="DataList_ItemBound"
Runat="Server" Width="500">
<HeaderTemplate>
<table border= "0">
</HeaderTemplate>
<ItemTemplate>
<tr>
<td class="dataTD" width= "100" >
<b>Start Date:</b>&nbsp;&nbsp;</b>
</td>
<td class="dataTD" width= "400">
<%# Container.DataItem("Start_Date") %>
</td>
</tr>
</ItemTemplate>
<SeparatorTemplate>
<tr>
<td colspan= "2" width= "500" align= "center">
<hr />
</td>
</tr>
</SeparatorTemplate>
<FooterTemplate>
<div align="center">
<tr>
<td colspan= "2" width= "500" align= "center">

</td>
</tr>
</table>
</FooterTemplate>
</asp:DataList>

Nov 19 '05 #4

P: n/a
It is from bad word-wrap. Move the line after line 266 up to the end of the
line? There shouldn't be a line break.

"bienwell" <bi******@hotmail.com> wrote in message
news:Og**************@tk2msftngp13.phx.gbl...
Ken,

It's exactly what I need. However, when I tried it, I've got this error :

Argument 'Expression' is not a valid value.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

Exception Details: System.ArgumentException: Argument 'Expression' is not
a
valid value.

Source Error:

Line 264: </td>
Line 265: <td class="dataTD" width= "400">
Line 266:
<%#Format(Container.DataItem("Start_Date"),
"d/M/yyyy") %>


================================================== ==========================
=========
"Ken Cox [Microsoft MVP]" <BA************@sympatico.ca> wrote in message
news:u9**************@TK2MSFTNGP12.phx.gbl...
It seems like a custom date format string should handle that. You can

insert
the function right in your HTML code as shown below.

Is that what you needed?

Ken
Microsoft MVP [ASP.NET]
Toronto

<form id="Form1" method="post" runat="server">
<asp:datalist id="myDataList"
OnItemDataBound="DataList_ItemBound" Runat="Server" Width="500">
<headertemplate>
<table border="0">
</headertemplate>
<itemtemplate>
<tr>
<td class="dataTD" width="100">
<b>Start Date:</b>&nbsp;&nbsp;</b>
</td>
<td class="dataTD" width="400">
<%#Format(Container.DataItem("Start_Date"),
"d/M/yyyy") %>
</td>
</tr>
</itemtemplate>
<separatortemplate>
<tr>
<td colspan="2" width="500" align="center">
<hr />
</td>
</tr>
</separatortemplate>
<footertemplate>
<div align="center">
<tr>
<td colspan="2" width="500" align="center">
</td>
</tr>
</table>
</footertemplate>
</asp:datalist>
</form>

Private Sub Page_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
If Not IsPostBack Then
myDataList.DataSource = CreateDataSource()
myDataList.DataBind()
End If
End Sub

Public Sub DataList_ItemBound(ByVal sender As Object, _
ByVal e As System.Web.UI.WebControls.DataListItemEventArgs)
End Sub
Function CreateDataSource() As DataTable
Dim dt As New DataTable
Dim dr As DataRow
dt.Columns.Add(New DataColumn _
("Start_Date", GetType(DateTime)))
Dim i As Integer
For i = 0 To 4
dr = dt.NewRow()
dr(0) = Now.AddDays(i)
dt.Rows.Add(dr)
Next i
Return dt
End Function 'CreateDataSource
"bienwell" <bi******@hotmail.com> wrote in message
news:ec**************@TK2MSFTNGP10.phx.gbl...
> Hi,
>
> I have a problem of displaying data bound by a datalist control. In my
> table, I have a field Start_date which has Short Date data type. I tried > to
> update this field by Current Date. After that, I display End_Date on
> the
> DataList control. The output looks like 3/18/2005 12:00:00 AM .
> I'd
> like to format data for this field to be 3/18/2005. Please help me.
>
> Thanks in advance.
> ================================================== ===================
> My DataList Control with the declaration as following:
>
> <asp:DataList id="myDataList" OnItemDataBound="DataList_ItemBound"
> Runat="Server" Width="500">
> <HeaderTemplate>
> <table border= "0">
> </HeaderTemplate>
> <ItemTemplate>
> <tr>
> <td class="dataTD" width= "100" >
> <b>Start Date:</b>&nbsp;&nbsp;</b>
> </td>
> <td class="dataTD" width= "400">
> <%# Container.DataItem("Start_Date") %>
> </td>
> </tr>
> </ItemTemplate>
> <SeparatorTemplate>
> <tr>
> <td colspan= "2" width= "500" align= "center">
> <hr />
> </td>
> </tr>
> </SeparatorTemplate>
> <FooterTemplate>
> <div align="center">
> <tr>
> <td colspan= "2" width= "500" align= "center">
>
> </td>
> </tr>
> </table>
> </FooterTemplate>
> </asp:DataList>
>
>



Nov 19 '05 #5

P: n/a
Line 266 shouldn't wrap. Make it look like this:

<%#Format(Container.DataItem("Start_Date"),"d/M/yyyy")%>

Let us know?
"bienwell" <bi******@hotmail.com> wrote in message
news:OT**************@tk2msftngp13.phx.gbl...
Ken,

It's exactly what I need. I've got this error message when I tried it:

Argument 'Expression' is not a valid value.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

Exception Details: System.ArgumentException: Argument 'Expression' is not
a
valid value.

Source Error:

Line 264: </td>
Line 265: <td class="dataTD" width= "400">
Line 266:
<%#Format(Container.DataItem("Start_Date"),
"d/M/yyyy") %>

================================================== ============

"Ken Cox [Microsoft MVP]" <BA************@sympatico.ca> wrote in message
news:u9**************@TK2MSFTNGP12.phx.gbl...
It seems like a custom date format string should handle that. You can

insert
the function right in your HTML code as shown below.

Is that what you needed?

Ken
Microsoft MVP [ASP.NET]
Toronto

<form id="Form1" method="post" runat="server">
<asp:datalist id="myDataList"
OnItemDataBound="DataList_ItemBound" Runat="Server" Width="500">
<headertemplate>
<table border="0">
</headertemplate>
<itemtemplate>
<tr>
<td class="dataTD" width="100">
<b>Start Date:</b>&nbsp;&nbsp;</b>
</td>
<td class="dataTD" width="400">
<%#Format(Container.DataItem("Start_Date"),
"d/M/yyyy") %>
</td>
</tr>
</itemtemplate>
<separatortemplate>
<tr>
<td colspan="2" width="500" align="center">
<hr />
</td>
</tr>
</separatortemplate>
<footertemplate>
<div align="center">
<tr>
<td colspan="2" width="500" align="center">
</td>
</tr>
</table>
</footertemplate>
</asp:datalist>
</form>

Private Sub Page_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
If Not IsPostBack Then
myDataList.DataSource = CreateDataSource()
myDataList.DataBind()
End If
End Sub

Public Sub DataList_ItemBound(ByVal sender As Object, _
ByVal e As System.Web.UI.WebControls.DataListItemEventArgs)
End Sub
Function CreateDataSource() As DataTable
Dim dt As New DataTable
Dim dr As DataRow
dt.Columns.Add(New DataColumn _
("Start_Date", GetType(DateTime)))
Dim i As Integer
For i = 0 To 4
dr = dt.NewRow()
dr(0) = Now.AddDays(i)
dt.Rows.Add(dr)
Next i
Return dt
End Function 'CreateDataSource
"bienwell" <bi******@hotmail.com> wrote in message
news:ec**************@TK2MSFTNGP10.phx.gbl...
> Hi,
>
> I have a problem of displaying data bound by a datalist control. In my
> table, I have a field Start_date which has Short Date data type. I tried > to
> update this field by Current Date. After that, I display End_Date on
> the
> DataList control. The output looks like 3/18/2005 12:00:00 AM .
> I'd
> like to format data for this field to be 3/18/2005. Please help me.
>
> Thanks in advance.
> ================================================== ===================
> My DataList Control with the declaration as following:
>
> <asp:DataList id="myDataList" OnItemDataBound="DataList_ItemBound"
> Runat="Server" Width="500">
> <HeaderTemplate>
> <table border= "0">
> </HeaderTemplate>
> <ItemTemplate>
> <tr>
> <td class="dataTD" width= "100" >
> <b>Start Date:</b>&nbsp;&nbsp;</b>
> </td>
> <td class="dataTD" width= "400">
> <%# Container.DataItem("Start_Date") %>
> </td>
> </tr>
> </ItemTemplate>
> <SeparatorTemplate>
> <tr>
> <td colspan= "2" width= "500" align= "center">
> <hr />
> </td>
> </tr>
> </SeparatorTemplate>
> <FooterTemplate>
> <div align="center">
> <tr>
> <td colspan= "2" width= "500" align= "center">
>
> </td>
> </tr>
> </table>
> </FooterTemplate>
> </asp:DataList>
>
>



Nov 19 '05 #6

P: n/a
Ken,

Still have that error message. Actually, I did it last time like this
<%#Format(Container.DataItem("Start_Date"), "d/M/yyyy") %> in one line
of the .aspx file and got that error message when running the page. It's
not because of word wrap. I cut and pasted the error message from Web page
and you saw it not in one line.

Thanks.

================================================== =======
"Ken Cox [Microsoft MVP]" <BA************@sympatico.ca> wrote in message
news:eK**************@TK2MSFTNGP09.phx.gbl...
Line 266 shouldn't wrap. Make it look like this:

<%#Format(Container.DataItem("Start_Date"),"d/M/yyyy")%>

Let us know?
"bienwell" <bi******@hotmail.com> wrote in message
news:OT**************@tk2msftngp13.phx.gbl...
Ken,

It's exactly what I need. I've got this error message when I tried it:

Argument 'Expression' is not a valid value.
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

Exception Details: System.ArgumentException: Argument 'Expression' is not a
valid value.

Source Error:

Line 264: </td>
Line 265: <td class="dataTD" width= "400">
Line 266:
<%#Format(Container.DataItem("Start_Date"),
"d/M/yyyy") %>

================================================== ============

"Ken Cox [Microsoft MVP]" <BA************@sympatico.ca> wrote in message
news:u9**************@TK2MSFTNGP12.phx.gbl...
It seems like a custom date format string should handle that. You can

insert
the function right in your HTML code as shown below.

Is that what you needed?

Ken
Microsoft MVP [ASP.NET]
Toronto

<form id="Form1" method="post" runat="server">
<asp:datalist id="myDataList"
OnItemDataBound="DataList_ItemBound" Runat="Server" Width="500">
<headertemplate>
<table border="0">
</headertemplate>
<itemtemplate>
<tr>
<td class="dataTD" width="100">
<b>Start Date:</b>&nbsp;&nbsp;</b>
</td>
<td class="dataTD" width="400">
<%#Format(Container.DataItem("Start_Date"),
"d/M/yyyy") %>
</td>
</tr>
</itemtemplate>
<separatortemplate>
<tr>
<td colspan="2" width="500" align="center">
<hr />
</td>
</tr>
</separatortemplate>
<footertemplate>
<div align="center">
<tr>
<td colspan="2" width="500" align="center">
</td>
</tr>
</table>
</footertemplate>
</asp:datalist>
</form>

Private Sub Page_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
If Not IsPostBack Then
myDataList.DataSource = CreateDataSource()
myDataList.DataBind()
End If
End Sub

Public Sub DataList_ItemBound(ByVal sender As Object, _
ByVal e As System.Web.UI.WebControls.DataListItemEventArgs)
End Sub
Function CreateDataSource() As DataTable
Dim dt As New DataTable
Dim dr As DataRow
dt.Columns.Add(New DataColumn _
("Start_Date", GetType(DateTime)))
Dim i As Integer
For i = 0 To 4
dr = dt.NewRow()
dr(0) = Now.AddDays(i)
dt.Rows.Add(dr)
Next i
Return dt
End Function 'CreateDataSource
"bienwell" <bi******@hotmail.com> wrote in message
news:ec**************@TK2MSFTNGP10.phx.gbl...
> Hi,
>
> I have a problem of displaying data bound by a datalist control. In my > table, I have a field Start_date which has Short Date data type. I

tried
> to
> update this field by Current Date. After that, I display End_Date on
> the
> DataList control. The output looks like 3/18/2005 12:00:00 AM .
> I'd
> like to format data for this field to be 3/18/2005. Please help me.
>
> Thanks in advance.
> ================================================== ===================
> My DataList Control with the declaration as following:
>
> <asp:DataList id="myDataList" OnItemDataBound="DataList_ItemBound"
> Runat="Server" Width="500">
> <HeaderTemplate>
> <table border= "0">
> </HeaderTemplate>
> <ItemTemplate>
> <tr>
> <td class="dataTD" width= "100" >
> <b>Start Date:</b>&nbsp;&nbsp;</b>
> </td>
> <td class="dataTD" width= "400">
> <%# Container.DataItem("Start_Date") %>
> </td>
> </tr>
> </ItemTemplate>
> <SeparatorTemplate>
> <tr>
> <td colspan= "2" width= "500" align= "center">
> <hr />
> </td>
> </tr>
> </SeparatorTemplate>
> <FooterTemplate>
> <div align="center">
> <tr>
> <td colspan= "2" width= "500" align= "center">
>
> </td>
> </tr>
> </table>
> </FooterTemplate>
> </asp:DataList>
>
>


Nov 19 '05 #7

P: n/a
Hmmm. I can't figure out why it doesn't work for you. The script is running
just fine on my Web page here:

http://www.kencox.ca/datalstscript.aspx

Here's the entire code for that page:

<%@ Page Language="vb" AutoEventWireup="true" %>
<%@ Import namespace="System.Data" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>datalstscript</title>
<meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" content="Visual Basic .NET 7.1">
<meta name=vs_defaultClientScript content="JavaScript">
<meta name=vs_targetSchema
content="http://schemas.microsoft.com/intellisense/ie5">
<script language="vb" runat="server">
Private Sub Page_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
If Not IsPostBack Then
myDataList.DataSource = CreateDataSource()
myDataList.DataBind()
End If
End Sub

Public Sub DataList_ItemBound(ByVal sender As Object, _
ByVal e As System.Web.UI.WebControls.DataListItemEventArgs)
End Sub
Function CreateDataSource() As DataTable
Dim dt As New DataTable
Dim dr As DataRow
dt.Columns.Add(New DataColumn _
("Start_Date", GetType(DateTime)))
Dim i As Integer
For i = 0 To 4
dr = dt.NewRow()
dr(0) = Now.AddDays(i)
dt.Rows.Add(dr)
Next i
Return dt
End Function 'CreateDataSource
</script>
</head>
<body MS_POSITIONING="FlowLayout">

<form id="Form1" method="post" runat="server">
<asp:datalist id="myDataList"
OnItemDataBound="DataList_ItemBound" Runat="Server" Width="500">
<headertemplate>
<table border="0">
</headertemplate>
<itemtemplate>
<tr>
<td class="dataTD" width="100">
<b>Start Date:</b>&nbsp;&nbsp;</b>
</td>
<td class="dataTD" width="400">
<%#Format(Container.DataItem("Start_Date"),"d/M/yyyy")%>
</td>
</tr>
</itemtemplate>
<separatortemplate>
<tr>
<td colspan="2" width="500" align="center">
<hr />
</td>
</tr>
</separatortemplate>
<footertemplate>
<div align="center">
<tr>
<td colspan="2" width="500" align="center">
</td>
</tr>
</table>
</footertemplate>
</asp:datalist>
</form>

</body>
</html>

Nov 19 '05 #8

P: n/a
Ken,

I've tried to run your code; it worked fine. I will take a look on my
program or run it in another PC to see what will happen.

Thanks.
================================================
"Ken Cox [Microsoft MVP]" <BA************@sympatico.ca> wrote in message
news:#p**************@tk2msftngp13.phx.gbl...
Hmmm. I can't figure out why it doesn't work for you. The script is running just fine on my Web page here:

http://www.kencox.ca/datalstscript.aspx

Here's the entire code for that page:

<%@ Page Language="vb" AutoEventWireup="true" %>
<%@ Import namespace="System.Data" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>datalstscript</title>
<meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" content="Visual Basic .NET 7.1">
<meta name=vs_defaultClientScript content="JavaScript">
<meta name=vs_targetSchema
content="http://schemas.microsoft.com/intellisense/ie5">
<script language="vb" runat="server">
Private Sub Page_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
If Not IsPostBack Then
myDataList.DataSource = CreateDataSource()
myDataList.DataBind()
End If
End Sub

Public Sub DataList_ItemBound(ByVal sender As Object, _
ByVal e As System.Web.UI.WebControls.DataListItemEventArgs)
End Sub
Function CreateDataSource() As DataTable
Dim dt As New DataTable
Dim dr As DataRow
dt.Columns.Add(New DataColumn _
("Start_Date", GetType(DateTime)))
Dim i As Integer
For i = 0 To 4
dr = dt.NewRow()
dr(0) = Now.AddDays(i)
dt.Rows.Add(dr)
Next i
Return dt
End Function 'CreateDataSource
</script>
</head>
<body MS_POSITIONING="FlowLayout">

<form id="Form1" method="post" runat="server">
<asp:datalist id="myDataList"
OnItemDataBound="DataList_ItemBound" Runat="Server" Width="500">
<headertemplate>
<table border="0">
</headertemplate>
<itemtemplate>
<tr>
<td class="dataTD" width="100">
<b>Start Date:</b>&nbsp;&nbsp;</b>
</td>
<td class="dataTD" width="400">
<%#Format(Container.DataItem("Start_Date"),"d/M/yyyy")%>
</td>
</tr>
</itemtemplate>
<separatortemplate>
<tr>
<td colspan="2" width="500" align="center">
<hr />
</td>
</tr>
</separatortemplate>
<footertemplate>
<div align="center">
<tr>
<td colspan="2" width="500" align="center">
</td>
</tr>
</table>
</footertemplate>
</asp:datalist>
</form>

</body>
</html>

Nov 19 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.