Bind Data to a Single Label Control: Possible?
Hi Folks:
How do you bind data to a single label control?
Code:
<script runat="server">
Protected Sub Page_Load(ByVal sender As Object, _
ByVal e As System.EventArgs)
If Not Page.IsPostBack Then
Dim MyConnection As SqlConnection
Dim MyCommand As SqlCommand
Dim MyReader As SqlDataReader
MyConnection = New SqlConnection()
MyConnection.ConnectionString = _
ConfigurationManager.ConnectionStrings("DSN_Northw ind").ConnectionString
MyCommand = New SqlCommand()
MyCommand.CommandText = "SELECT ID, CustomerName FROM CUSTOMERS"
MyCommand.CommandType = CommandType.Text
MyCommand.Connection = MyConnection
MyCommand.Connection.Open()
MyReader = MyCommand.ExecuteReader(CommandBehavior.CloseConne ction)
?????????????????????? WHAT GOES HERE ?????????????????????
MyCommand.Dispose()
MyConnection.Dispose()
End If
End Sub
</script>
Then, in the page:
<asp:Label ID="Label1" runat="server" Text="Label"><%# CustomerName %></asp:Label>
Is this possible in ASP.NET? I don't want to use gridview, detailsview, formview, repeater, etc... I just want to quickly bind a headline or single database field to a label or literal control.
Chris
|