|
 |
aspx thread: Help on DataBinding needed
Message #1 by "Alem" <alem.orlic@z...> on Tue, 13 Mar 2001 08:35:22
|
|
Is it possible to bind datalist to data source only using class code
(without usage of <%# %> syntax in the aspx code).
Thnx.
Message #2 by "Dave Sussman" <davids@i...> on Thu, 15 Mar 2001 16:13:13 -0000
|
|
Yes, something like this:
<script language="VB" runat="server">
Sub Page_Load(Source As Object, E As EventArgs)
Dim myConnection As ADOConnection
Dim myCommand As ADODataSetCommand
Dim ConnStr As String
Dim SQL As String
' set the connection details
ConnStr = "Provider=SQLOLEDB; Data Source=(local); Initial
Catalog=AdvWorks; User ID=sa"
SQL = "select * from Products"
myConnection = New ADOConnection(ConnStr)
myCommand = New ADODataSetCommand(SQL, myConnection)
Dim ds As New DataSet
myCommand.FillDataSet(ds, "Products")
ListBox1.DataSource=ds.Tables("Products").DefaultView
ListBox1.DataBind()
End Sub
</script>
<asp:ListBox id="ListBox1" runat="server"
DataTextField="ProductName" DataValueField="ProductID"/>
Dave
"Alem" <alem.orlic@z...> wrote in message news:47260@a...
>
> Is it possible to bind datalist to data source only using class code
> (without usage of <%# %> syntax in the aspx code).
>
> Thnx.
>
>
Message #3 by "Alem" <alem.orlic@z...> on Fri, 16 Mar 2001 08:39:32
|
|
Thank you for the effort, but I know how to bind Listbox. Maybe I was not
precise enough. My question was about Datalist that contains other web
controls that are bound to fields from data source. Something like this:
<asp:datalist id="list1" runat="server">
<template name="itemtemplate">
<asp:label id='<%# databinder.eval
(Container.dataitem, "ID", "ProductID{0}")' text='<%# databinder.eval
(Container.dataitem, "ID")' runat="server"/>
<asp:label id='<%# databinder.eval
(Container.dataitem, "Name", "ProductName{0}")'text='<%# databinder.eval
(Container.dataitem, "Name")' runat="server"/>
</template>
</asp:datalist>
I'd like to put all data binding done in aspx file into class (codebehind)
file. Is that possible or not?
Message #4 by "Dave Sussman" <davids@i...> on Fri, 16 Mar 2001 15:24:32 -0000
|
|
What's wrong with the code you've got? Below is a sample I use often - the
datalist is bound as in my previous example, and then you bind each item.
<asp:DataList id="DataGrid1" border="0"
RepeatDirection="Horizontal" RepeatColumns="4"
runat="server">
<template name="itemtemplate">
<table>
<tr><td>
<asp:Hyperlink ImageURL='<%# Container.DataItem("ProductImageURL")
%>'
NavigateURL='<%# DataBinder.Eval(Container.DataItem,
"ProductID", "ShowProductDetails.aspx?PID={0}") %>'
target="_blank" runat="server" />
</td></tr>
<tr><td>
<b><%# Container.DataItem("ProductName") %></b><br>
<font size="-1">
<%# Container.DataItem("ProductCode") %><br>
$<%# Container.DataItem("UnitPrice") %>
</font>
</td></tr>
</table>
</template>
</asp:DataList>
Dave
"Alem" <alem.orlic@z...> wrote in message news:48382@a...
>
> Thank you for the effort, but I know how to bind Listbox. Maybe I was not
> precise enough. My question was about Datalist that contains other web
> controls that are bound to fields from data source. Something like this:
>
> <asp:datalist id="list1" runat="server">
> <template name="itemtemplate">
> <asp:label id='<%# databinder.eval
> (Container.dataitem, "ID", "ProductID{0}")' text='<%# databinder.eval
> (Container.dataitem, "ID")' runat="server"/>
> <asp:label id='<%# databinder.eval
> (Container.dataitem, "Name", "ProductName{0}")'text='<%# databinder.eval
> (Container.dataitem, "Name")' runat="server"/>
> </template>
> </asp:datalist>
>
> I'd like to put all data binding done in aspx file into class (codebehind)
> file. Is that possible or not?
>
>
Message #5 by "Susan Warren" <swarren@m...> on Fri, 16 Mar 2001 07:12:36 -0800
|
|
DataBinding a control with a template using the declarative syntax, as
below, does work. (Be sure to call DataBind() in your code.) But your
databinding syntax looks a little wrong... Do you really have a field in
your data source named "ProductID{0}" ?
-----Original Message-----
From: Alem [mailto:alem.orlic@z...]
Sent: Friday, March 16, 2001 12:40 AM
To: ASP+
Subject: [aspx] Re: Help on DataBinding needed
Thank you for the effort, but I know how to bind Listbox. Maybe I was
not
precise enough. My question was about Datalist that contains other web
controls that are bound to fields from data source. Something like this:
<asp:datalist id=3D"list1" runat=3D"server">
<template name=3D"itemtemplate">
<asp:label id=3D'<%# databinder.eval
(Container.dataitem, "ID", "ProductID{0}")' text=3D'<%# databinder.eval
(Container.dataitem, "ID")' runat=3D"server"/>
<asp:label id=3D'<%# databinder.eval
(Container.dataitem, "Name", "ProductName{0}")'text=3D'<%#
databinder.eval
(Container.dataitem, "Name")' runat=3D"server"/>
</template>
</asp:datalist>
I'd like to put all data binding done in aspx file into class
(codebehind)
file. Is that possible or not?
|
|
 |