473,467 Members | 1,307 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

How to format databound by DataList Control ?

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
8 5873
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
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
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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Phil Townsend | last post by:
I want to add a datalist to a Repeater control. The data for the datalist resides in a cached DataSet that contains two related tables. The data in last child table should be rendered in three...
0
by: Steve | last post by:
Hi, I have a problem here with bounding data inside a datalist. Currently I am working on a page which I can have a list of items using a datalist(listA). Inside this datalist(listA) i would...
1
by: rodchar | last post by:
hey all, i have a label inside an item template of a datalist control. the datasource field type is money. well, when i databind the money field to the label.text it show a precision of 4....
7
by: | last post by:
I'm using ASP.NET 2.0, C#, SQL Server 2005, and databound controls like the DataList and the GridView. Right now I'm using SqlDataSource as part of very quick and dirty site; I'm not looking to...
2
by: rn5a | last post by:
I am using a DataList control to display records from a database table. The records are being rendered in a HTML table which is within the DataList....something like this: <form runat="server">...
4
by: Derty | last post by:
Any way to limit the length of databound text on a datalist itemtemplate?
2
by: mianiro | last post by:
Does a control such as a gridview or datalist still load with data when it is bound to a dataset but the visibility is = False?? I have a datalist and a gridview with datasources set at design...
4
by: =?Utf-8?B?ZGNoMw==?= | last post by:
Is there a way to conditionally format a dateTime field to produce on result if the value is 10/31/2008 12:00 AM (user didn't enter a time) and another result if the value is 10/31/2008 5:30 PM...
1
by: David C | last post by:
I am trying to get a LinkButton to show a formatted date as part of the text but it is not working. Below is what I have. MealDate is a valid date, e.g. 11/17/2008. I want it to come out like...
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
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
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
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,...
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...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.