473,749 Members | 2,580 Online
Bytes | Software Development & Data Engineering Community
+ 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_Item Bound"
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.DataI tem("Start_Date ") %>
</td>
</tr>
</ItemTemplate>
<SeparatorTempl ate>
<tr>
<td colspan= "2" width= "500" align= "center">
<hr />
</td>
</tr>
</SeparatorTempla te>
<FooterTemplate >
<div align="center">
<tr>
<td colspan= "2" width= "500" align= "center">

</td>
</tr>
</table>
</FooterTemplate>
</asp:DataList>
Nov 19 '05 #1
8 5890
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_Item Bound" 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(Conta iner.DataItem(" Start_Date"),
"d/M/yyyy") %>
</td>
</tr>
</itemtemplate>
<separatortempl ate>
<tr>
<td colspan="2" width="500" align="center">
<hr />
</td>
</tr>
</separatortempla te>
<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.EventArg s) Handles MyBase.Load
If Not IsPostBack Then
myDataList.Data Source = CreateDataSourc e()
myDataList.Data Bind()
End If
End Sub

Public Sub DataList_ItemBo und(ByVal sender As Object, _
ByVal e As System.Web.UI.W ebControls.Data ListItemEventAr gs)
End Sub
Function CreateDataSourc e() As DataTable
Dim dt As New DataTable
Dim dr As DataRow
dt.Columns.Add( New DataColumn _
("Start_Date ", GetType(DateTim e)))
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 'CreateDataSour ce
"bienwell" <bi******@hotma il.com> wrote in message
news:ec******** ******@TK2MSFTN GP10.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_Item Bound"
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.DataI tem("Start_Date ") %>
</td>
</tr>
</ItemTemplate>
<SeparatorTempl ate>
<tr>
<td colspan= "2" width= "500" align= "center">
<hr />
</td>
</tr>
</SeparatorTempla te>
<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.Argument Exception: Argument 'Expression' is not a
valid value.

Source Error:

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


=============== =============== =============== =============== =============== =
=========
"Ken Cox [Microsoft MVP]" <BA************ @sympatico.ca> wrote in message
news:u9******** ******@TK2MSFTN GP12.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_Item Bound" 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(Conta iner.DataItem(" Start_Date"),
"d/M/yyyy") %>
</td>
</tr>
</itemtemplate>
<separatortempl ate>
<tr>
<td colspan="2" width="500" align="center">
<hr />
</td>
</tr>
</separatortempla te>
<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.EventArg s) Handles MyBase.Load
If Not IsPostBack Then
myDataList.Data Source = CreateDataSourc e()
myDataList.Data Bind()
End If
End Sub

Public Sub DataList_ItemBo und(ByVal sender As Object, _
ByVal e As System.Web.UI.W ebControls.Data ListItemEventAr gs)
End Sub
Function CreateDataSourc e() As DataTable
Dim dt As New DataTable
Dim dr As DataRow
dt.Columns.Add( New DataColumn _
("Start_Date ", GetType(DateTim e)))
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 'CreateDataSour ce
"bienwell" <bi******@hotma il.com> wrote in message
news:ec******** ******@TK2MSFTN GP10.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_Item Bound"
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.DataI tem("Start_Date ") %>
</td>
</tr>
</ItemTemplate>
<SeparatorTempl ate>
<tr>
<td colspan= "2" width= "500" align= "center">
<hr />
</td>
</tr>
</SeparatorTempla te>
<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.Argument Exception: Argument 'Expression' is not a
valid value.

Source Error:

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

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

"Ken Cox [Microsoft MVP]" <BA************ @sympatico.ca> wrote in message
news:u9******** ******@TK2MSFTN GP12.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_Item Bound" 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(Conta iner.DataItem(" Start_Date"),
"d/M/yyyy") %>
</td>
</tr>
</itemtemplate>
<separatortempl ate>
<tr>
<td colspan="2" width="500" align="center">
<hr />
</td>
</tr>
</separatortempla te>
<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.EventArg s) Handles MyBase.Load
If Not IsPostBack Then
myDataList.Data Source = CreateDataSourc e()
myDataList.Data Bind()
End If
End Sub

Public Sub DataList_ItemBo und(ByVal sender As Object, _
ByVal e As System.Web.UI.W ebControls.Data ListItemEventAr gs)
End Sub
Function CreateDataSourc e() As DataTable
Dim dt As New DataTable
Dim dr As DataRow
dt.Columns.Add( New DataColumn _
("Start_Date ", GetType(DateTim e)))
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 'CreateDataSour ce
"bienwell" <bi******@hotma il.com> wrote in message
news:ec******** ******@TK2MSFTN GP10.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_Item Bound"
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.DataI tem("Start_Date ") %>
</td>
</tr>
</ItemTemplate>
<SeparatorTempl ate>
<tr>
<td colspan= "2" width= "500" align= "center">
<hr />
</td>
</tr>
</SeparatorTempla te>
<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******@hotma il.com> wrote in message
news:Og******** ******@tk2msftn gp13.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.Argument Exception: Argument 'Expression' is not
a
valid value.

Source Error:

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


=============== =============== =============== =============== =============== =
=========
"Ken Cox [Microsoft MVP]" <BA************ @sympatico.ca> wrote in message
news:u9******** ******@TK2MSFTN GP12.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_Item Bound" 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(Conta iner.DataItem(" Start_Date"),
"d/M/yyyy") %>
</td>
</tr>
</itemtemplate>
<separatortempl ate>
<tr>
<td colspan="2" width="500" align="center">
<hr />
</td>
</tr>
</separatortempla te>
<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.EventArg s) Handles MyBase.Load
If Not IsPostBack Then
myDataList.Data Source = CreateDataSourc e()
myDataList.Data Bind()
End If
End Sub

Public Sub DataList_ItemBo und(ByVal sender As Object, _
ByVal e As System.Web.UI.W ebControls.Data ListItemEventAr gs)
End Sub
Function CreateDataSourc e() As DataTable
Dim dt As New DataTable
Dim dr As DataRow
dt.Columns.Add( New DataColumn _
("Start_Date ", GetType(DateTim e)))
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 'CreateDataSour ce
"bienwell" <bi******@hotma il.com> wrote in message
news:ec******** ******@TK2MSFTN GP10.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_Item Bound"
> 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.DataI tem("Start_Date ") %>
> </td>
> </tr>
> </ItemTemplate>
> <SeparatorTempl ate>
> <tr>
> <td colspan= "2" width= "500" align= "center">
> <hr />
> </td>
> </tr>
> </SeparatorTempla te>
> <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(Conta iner.DataItem(" Start_Date"),"d/M/yyyy")%>

Let us know?
"bienwell" <bi******@hotma il.com> wrote in message
news:OT******** ******@tk2msftn gp13.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.Argument Exception: Argument 'Expression' is not
a
valid value.

Source Error:

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

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

"Ken Cox [Microsoft MVP]" <BA************ @sympatico.ca> wrote in message
news:u9******** ******@TK2MSFTN GP12.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_Item Bound" 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(Conta iner.DataItem(" Start_Date"),
"d/M/yyyy") %>
</td>
</tr>
</itemtemplate>
<separatortempl ate>
<tr>
<td colspan="2" width="500" align="center">
<hr />
</td>
</tr>
</separatortempla te>
<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.EventArg s) Handles MyBase.Load
If Not IsPostBack Then
myDataList.Data Source = CreateDataSourc e()
myDataList.Data Bind()
End If
End Sub

Public Sub DataList_ItemBo und(ByVal sender As Object, _
ByVal e As System.Web.UI.W ebControls.Data ListItemEventAr gs)
End Sub
Function CreateDataSourc e() As DataTable
Dim dt As New DataTable
Dim dr As DataRow
dt.Columns.Add( New DataColumn _
("Start_Date ", GetType(DateTim e)))
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 'CreateDataSour ce
"bienwell" <bi******@hotma il.com> wrote in message
news:ec******** ******@TK2MSFTN GP10.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_Item Bound"
> 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.DataI tem("Start_Date ") %>
> </td>
> </tr>
> </ItemTemplate>
> <SeparatorTempl ate>
> <tr>
> <td colspan= "2" width= "500" align= "center">
> <hr />
> </td>
> </tr>
> </SeparatorTempla te>
> <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(Conta iner.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******** ******@TK2MSFTN GP09.phx.gbl...
Line 266 shouldn't wrap. Make it look like this:

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

Let us know?
"bienwell" <bi******@hotma il.com> wrote in message
news:OT******** ******@tk2msftn gp13.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.Argument Exception: Argument 'Expression' is not a
valid value.

Source Error:

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

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

"Ken Cox [Microsoft MVP]" <BA************ @sympatico.ca> wrote in message
news:u9******** ******@TK2MSFTN GP12.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_Item Bound" 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(Conta iner.DataItem(" Start_Date"),
"d/M/yyyy") %>
</td>
</tr>
</itemtemplate>
<separatortempl ate>
<tr>
<td colspan="2" width="500" align="center">
<hr />
</td>
</tr>
</separatortempla te>
<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.EventArg s) Handles MyBase.Load
If Not IsPostBack Then
myDataList.Data Source = CreateDataSourc e()
myDataList.Data Bind()
End If
End Sub

Public Sub DataList_ItemBo und(ByVal sender As Object, _
ByVal e As System.Web.UI.W ebControls.Data ListItemEventAr gs)
End Sub
Function CreateDataSourc e() As DataTable
Dim dt As New DataTable
Dim dr As DataRow
dt.Columns.Add( New DataColumn _
("Start_Date ", GetType(DateTim e)))
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 'CreateDataSour ce
"bienwell" <bi******@hotma il.com> wrote in message
news:ec******** ******@TK2MSFTN GP10.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_Item Bound"
> 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.DataI tem("Start_Date ") %>
> </td>
> </tr>
> </ItemTemplate>
> <SeparatorTempl ate>
> <tr>
> <td colspan= "2" width= "500" align= "center">
> <hr />
> </td>
> </tr>
> </SeparatorTempla te>
> <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="Syst em.Data" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>datalsts cript</title>
<meta name="GENERATOR " content="Micros oft Visual Studio .NET 7.1">
<meta name="CODE_LANG UAGE" content="Visual Basic .NET 7.1">
<meta name=vs_default ClientScript content="JavaSc ript">
<meta name=vs_targetS chema
content="http://schemas.microso ft.com/intellisense/ie5">
<script language="vb" runat="server">
Private Sub Page_Load(ByVal sender As System.Object, _
ByVal e As System.EventArg s) Handles MyBase.Load
If Not IsPostBack Then
myDataList.Data Source = CreateDataSourc e()
myDataList.Data Bind()
End If
End Sub

Public Sub DataList_ItemBo und(ByVal sender As Object, _
ByVal e As System.Web.UI.W ebControls.Data ListItemEventAr gs)
End Sub
Function CreateDataSourc e() As DataTable
Dim dt As New DataTable
Dim dr As DataRow
dt.Columns.Add( New DataColumn _
("Start_Date ", GetType(DateTim e)))
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 'CreateDataSour ce
</script>
</head>
<body MS_POSITIONING= "FlowLayout ">

<form id="Form1" method="post" runat="server">
<asp:datalist id="myDataList "
OnItemDataBound ="DataList_Item Bound" 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(Conta iner.DataItem(" Start_Date"),"d/M/yyyy")%>
</td>
</tr>
</itemtemplate>
<separatortempl ate>
<tr>
<td colspan="2" width="500" align="center">
<hr />
</td>
</tr>
</separatortempla te>
<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******** ******@tk2msftn gp13.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="Syst em.Data" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>datalsts cript</title>
<meta name="GENERATOR " content="Micros oft Visual Studio .NET 7.1">
<meta name="CODE_LANG UAGE" content="Visual Basic .NET 7.1">
<meta name=vs_default ClientScript content="JavaSc ript">
<meta name=vs_targetS chema
content="http://schemas.microso ft.com/intellisense/ie5">
<script language="vb" runat="server">
Private Sub Page_Load(ByVal sender As System.Object, _
ByVal e As System.EventArg s) Handles MyBase.Load
If Not IsPostBack Then
myDataList.Data Source = CreateDataSourc e()
myDataList.Data Bind()
End If
End Sub

Public Sub DataList_ItemBo und(ByVal sender As Object, _
ByVal e As System.Web.UI.W ebControls.Data ListItemEventAr gs)
End Sub
Function CreateDataSourc e() As DataTable
Dim dt As New DataTable
Dim dr As DataRow
dt.Columns.Add( New DataColumn _
("Start_Date ", GetType(DateTim e)))
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 'CreateDataSour ce
</script>
</head>
<body MS_POSITIONING= "FlowLayout ">

<form id="Form1" method="post" runat="server">
<asp:datalist id="myDataList "
OnItemDataBound ="DataList_Item Bound" 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(Conta iner.DataItem(" Start_Date"),"d/M/yyyy")%>
</td>
</tr>
</itemtemplate>
<separatortempl ate>
<tr>
<td colspan="2" width="500" align="center">
<hr />
</td>
</tr>
</separatortempla te>
<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
3696
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 columns, so I have decided on a DataList control for this purpose. A repeater will render values from the parent table. I am attempting to call the ItemDataBound event of the Repeater control to build a DataList and render it to the page. I have...
0
1255
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 like to bound with another datalist(listB) so I am able to list items in listB based on the unique value on listA. here's the code that I kinda have...
1
1318
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. what's the best way to make that a precision of 2? thanks, rodchar
7
1756
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 tier things. I want the topmost/first data element in a particular control to NOT be displayed. This should be possible by either telling the renderer to hide the first element programmatically, or by deleting it from the data store that it has...
2
2049
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"> <asp:DataList ID="dlItem" AlternatingItemStyle-BackColor="lavender" ItemStyle-BackColor="pink" runat="server"> <HeaderTemplate> <table width="100%">
4
2956
by: Derty | last post by:
Any way to limit the length of databound text on a datalist itemtemplate?
2
1670
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 time. The visible property is set to False at design time as well. When the program runs ... I set the datalist to visible = True. However, no data appears in the datalist. Thanks for the help!
4
3049
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 (user entered a time). I'm looking for this result... Value Result 10/31/2008 12:00 AM FRI 10/31/08 10/31/2008 12:01 AM FRI 10/31/08 12:01 AM I also need to figure out the cell spacing to force the time...
1
5248
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 "Novenber 17". Below is my button settings. Thanks. David <asp:LinkButton ID="LinkButton1" runat="server" Text='Sun<br /><%# String.Format(Eval("MealDate","{0:MMMM dd}") %>' Width="110" CommandArgument='<%# Eval("MealDate", "{0:d}") %>'
0
8997
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 usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9568
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9389
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 captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9335
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 most users, this new feature is actually very convenient. If you want to control the update process,...
0
9256
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6801
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6079
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4881
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2218
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.