How do I bind a repeater?

T

timmso

I got this sample of code from Mike Moore in response to my question of how
I create clickable links from a data source.

<asp:Repeater id="Repeater1" runat="server">
<ItemTemplate>
<asp:HyperLink id="HyperLink1" runat="server" NavigateUrl='<%#
"http://localhost/ngrid1/repeater.aspx?a=" & Container.DataItem("au_lname")
%>'>'<%# DataBinder.Eval(Container.DataItem, "au_fname")%>'</asp:HyperLink>
<br>
</ItemTemplate>
</asp:Repeater>

How do I bind this to a datareader?

I have some code that works with a datagrid using the Northwind database
This is from the book Beginning Asp.Net Databases Using VB.Net, customized
for my question.

How do I "incorporate" the repeater here? I suppose I would remove the
datagrid portion and insert the repeater code. Can somebody please assist me
in this conversion? I'd like to see a structured layout like the datagrid
provides, but instead of just text, I'd like there to be links that can be
clicked, which would redirect me to a page that allowed me to use the ID for
some other purpose.

'--------------- begin
<%@ Import namespace="System.Data" %>
<%@ Import namespace="System.Data.SqlClient" %>

<html>
<head>
<title>Data Reader</title>
</head>
<body>
<asp:DataGrid id="dgData" runat="server" />
</body>
</html>

<script language="VB" runat="server">
Sub Page_Load(Source As Object, E As EventArgs)

Dim strConnection As String = ConfigurationSettings.AppSettings("NWind")
Dim objConnection As New SqlConnection(strConnection)
objConnection.Open()

' Get and display count
Dim strSQLcount As String
strSQLcount = "SELECT CategoryID, Description FROM Categories"

Dim objCommand As New SqlCommand(strSQLcount, objConnection)
Dim objReader As SqlDataReader = objCommand.ExecuteReader()

dgData.DataSource = objReader
dgData.DataBind()

objReader.Close()
objConnection.Close()

End Sub
</script>
'-------------------------end
 
J

Jos

timmso said:
I got this sample of code from Mike Moore in response to my question
of how I create clickable links from a data source.

<asp:Repeater id="Repeater1" runat="server">
<ItemTemplate>
<asp:HyperLink id="HyperLink1" runat="server" NavigateUrl='<%#
"http://localhost/ngrid1/repeater.aspx?a=" &
Container.DataItem("au_lname") %>'>'<%#
DataBinder.Eval(Container.DataItem,
"au_fname")%>'</asp:HyperLink> <br> </ItemTemplate>
</asp:Repeater>

How do I bind this to a datareader?

I have some code that works with a datagrid using the Northwind
database This is from the book Beginning Asp.Net Databases Using
VB.Net, customized for my question.

How do I "incorporate" the repeater here? I suppose I would remove the
datagrid portion and insert the repeater code. Can somebody please
assist me in this conversion? I'd like to see a structured layout
like the datagrid provides, but instead of just text, I'd like there
to be links that can be clicked, which would redirect me to a page
that allowed me to use the ID for some other purpose.

'--------------- begin
<%@ Import namespace="System.Data" %>
<%@ Import namespace="System.Data.SqlClient" %>

<html>
<head>
<title>Data Reader</title>
</head>
<body>
<asp:DataGrid id="dgData" runat="server" />
</body>
</html>

<script language="VB" runat="server">
Sub Page_Load(Source As Object, E As EventArgs)

Dim strConnection As String =
ConfigurationSettings.AppSettings("NWind") Dim objConnection As New
SqlConnection(strConnection) objConnection.Open()

' Get and display count
Dim strSQLcount As String
strSQLcount = "SELECT CategoryID, Description FROM Categories"

Dim objCommand As New SqlCommand(strSQLcount, objConnection)
Dim objReader As SqlDataReader = objCommand.ExecuteReader()

dgData.DataSource = objReader
dgData.DataBind()

objReader.Close()
objConnection.Close()

End Sub
</script>
'-------------------------end

1) Replace dgData by Repeater1.
2) Replace au_lname and au_fname by CategoryID and Description respectively.

That's all.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top