R
rn5a
Consider the following code:
<script runat="server">
Sub ShowData(obj As Object, ea As EventArgs)
lblDate.Text = DateTime.Now.ToString("d")
lblDate.DataBind()
End Sub
</script>
<form runat="server">
<asp:Label ID="lblDate" OnDataBinding="ShowData" runat="server"/>
</form>
But the Label doesn't display the current date. Why?
If I replace the OnDataBinding event with OnInit or OnLoad or
OnPreRender in the Label control, then the Label displays the current
date.
Actually the Form has a DataList as well after the Label control.
Records from a SQL Server 2005 DB table are displayed in the DataList
using SqlDataReader. One of the columns in the DB table is named
'OrderDate' which gets populated with the date (along with the time) on
which a user has placed an order.
I want to display the date on which the order was placed by a
particular customer in the Label control while the DataList should
display the rest of the records existing in the other DB table columns.
To render the order date in the Label, I can use
While (sqlReader.Read)
lblDate.Text = "Your order was placed on " &
sqlReader.GetDateTime(5).ToString("d")
End While
But since SqlDataReader is read-only, even if I do something like this
after the While (SqlReader.Read) code snippet
DataList1.DataSource = sqlReader
DataList1.DataBind()
the DataList won't display the rest of the records. I need to first
display the order date in the Label followed by the rest of the records
in the DataList. How do I accomplish this?
Please note that I want to do this using SqlDataReader only (not
SqlDataAdapter or any other object).
<script runat="server">
Sub ShowData(obj As Object, ea As EventArgs)
lblDate.Text = DateTime.Now.ToString("d")
lblDate.DataBind()
End Sub
</script>
<form runat="server">
<asp:Label ID="lblDate" OnDataBinding="ShowData" runat="server"/>
</form>
But the Label doesn't display the current date. Why?
If I replace the OnDataBinding event with OnInit or OnLoad or
OnPreRender in the Label control, then the Label displays the current
date.
Actually the Form has a DataList as well after the Label control.
Records from a SQL Server 2005 DB table are displayed in the DataList
using SqlDataReader. One of the columns in the DB table is named
'OrderDate' which gets populated with the date (along with the time) on
which a user has placed an order.
I want to display the date on which the order was placed by a
particular customer in the Label control while the DataList should
display the rest of the records existing in the other DB table columns.
To render the order date in the Label, I can use
While (sqlReader.Read)
lblDate.Text = "Your order was placed on " &
sqlReader.GetDateTime(5).ToString("d")
End While
But since SqlDataReader is read-only, even if I do something like this
after the While (SqlReader.Read) code snippet
DataList1.DataSource = sqlReader
DataList1.DataBind()
the DataList won't display the rest of the records. I need to first
display the order date in the Label followed by the rest of the records
in the DataList. How do I accomplish this?
Please note that I want to do this using SqlDataReader only (not
SqlDataAdapter or any other object).