473,386 Members | 1,793 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

How do I bind a repeater?

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
Nov 18 '05 #1
2 1528
Jos
timmso wrote:
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.

--

Jos Branders
Nov 18 '05 #2
Awesome...thanks!
"Jos" <jo***************@fastmail.fm> wrote in message
news:O2**************@tk2msftngp13.phx.gbl...
timmso wrote:
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.

--

Jos Branders

Nov 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Frank | last post by:
Hi alll, How can I bind a dynamically created dataTable to a repeater? I do not know the number of columns and the column names at design time. I try to do the same thing as for datagrid:...
3
by: AFN | last post by:
I need to manually create the data to be shown in a datagrid (or some data table object). Should I create an array and bind the array to the datagrid OR should I create a temporary dataset and...
6
by: Zenobia | last post by:
Hello folks, How do I bind an array to a repeater? or bind an array to a hyperlink (which is repeated inside a repeater) ? I get this message: Compiler Error Message: BC30456: 'DataItem'...
2
by: A Traveler | last post by:
Hi, I have a custom collection class i wrote, LineItemsCollection, which is a strongly typed collection of objects of my LineItem class. The LineItem class is a simple class with just a couple...
5
by: Jaybuffet | last post by:
a custom object. Similar to how I bind a collection of objects to a repeater. Is there a way to bind a single object to a Table? I could use a repeater, but seems over kill for a single object....
0
by: JP2006 | last post by:
I'm having an issue with a control I'm writing to consume RSS feeds. It gets a feed via a querystring parameter and sticks it in a dataset. I then use the dataset to write out the feed title and...
3
by: =?Utf-8?B?RGF2aWQgVGhpZWxlbg==?= | last post by:
Hi; I have a Repeater control where in my code-behind I call: rptrProducts.DataSource = cart.CartItems; rptrProducts.DataBind(); And then in the aspx file I have: <asp:TextBox...
4
by: Pieter | last post by:
Hi, I want to bind a proeprty of a child object to a DataGridView, but it doesn't work. For instance: Imagen that I have an object Company, and this object company has a child object...
2
by: akshalika | last post by:
Hi, I have a repeater control. it dynamically bind textbox or dropdown base on some condition. i want to bind required field validator dynamically for validate textbox or dropdown. here is my...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.