How do I bind a repeater?

  • Thread starter Thread starter timmso
  • Start date Start date
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
 
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.
 
Back
Top