473,505 Members | 13,904 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Repeater + Getting Column Names at Runtime

My SQL might generate a result like this:
Security 2005-06-30 2005-03-31 2004-12-31
IBM $65 $100 $123
(etc)

or like this:

Security 2005-06-30 2005-03-31
IBM $65 $100
(etc)

In other words, I don't know the number of columns until runtime. This
presents a problem in my repeater logic.

In the past I might do something like this:

==========================

<asp:Repeater id="dl" runat="server" EnableViewState="false">
<ItemTemplate>

<%# DataBinder.Eval(Container.DataItem, "Security")
<%# DataBinder.Eval(Container.DataItem, "2005-06-30") %>
<%# DataBinder.Eval(Container.DataItem, "2005-03-31") %>
<%# DataBinder.Eval(Container.DataItem, "2005-12-31") %>

</ItemTemplate>
</asp:Repeater>

==========================
This repeater will fail, however, if I have more or fewer date columns
than indicated.

So, the question is: how do I specify the number of columns at runtime?
Can I do a loop inside my repeater somehow?

I'd sure appreciate any help!

--Brent
Nov 19 '05 #1
4 4047
"Brent" <""b b i g l e r "@ y a h o o ." wrote:
My SQL might generate a result like this:
Security 2005-06-30 2005-03-31 2004-12-31
IBM $65 $100 $123
(etc)

or like this:

Security 2005-06-30 2005-03-31
IBM $65 $100
(etc)

In other words, I don't know the number of columns until runtime. This
presents a problem in my repeater logic.

In the past I might do something like this:

==========================

<asp:Repeater id="dl" runat="server" EnableViewState="false">
<ItemTemplate>

<%# DataBinder.Eval(Container.DataItem, "Security")
<%# DataBinder.Eval(Container.DataItem, "2005-06-30") %>
<%# DataBinder.Eval(Container.DataItem, "2005-03-31") %>
<%# DataBinder.Eval(Container.DataItem, "2005-12-31") %>

</ItemTemplate>
</asp:Repeater>

==========================
This repeater will fail, however, if I have more or fewer date columns
than indicated.

So, the question is: how do I specify the number of columns at runtime?
Can I do a loop inside my repeater somehow?

I'd sure appreciate any help!

--Brent


You can create 2 repeater templates (e.g., MyTemplate1 and MyTemplate2)
dynamically as in this MSDN sample:
http://msdn.microsoft.com/library/de...ynamically.asp

At run time, based on which dataset you would databind, you would assign
which template to use:

Repeater1.ItemTemplate = new MyTemplate1(ListItemType.Item);
or
Repeater1.ItemTemplate = new MyTemplate2(ListItemType.Item);

--
HTH,
Phillip Williams

Nov 19 '05 #2
perhaps build the html in the repeater from the codebehind in the
ITEM_DATABOUND event of the repeater, instead of trying to do it all from the
ASPX view?

--
Curt Christianson
site: http://www.darkfalz.com
blog: http://blog.darkfalz.com

"Brent" <""b b i g l e r "@ y a h o o ." wrote:
My SQL might generate a result like this:
Security 2005-06-30 2005-03-31 2004-12-31
IBM $65 $100 $123
(etc)

or like this:

Security 2005-06-30 2005-03-31
IBM $65 $100
(etc)

In other words, I don't know the number of columns until runtime. This
presents a problem in my repeater logic.

In the past I might do something like this:

==========================

<asp:Repeater id="dl" runat="server" EnableViewState="false">
<ItemTemplate>

<%# DataBinder.Eval(Container.DataItem, "Security")
<%# DataBinder.Eval(Container.DataItem, "2005-06-30") %>
<%# DataBinder.Eval(Container.DataItem, "2005-03-31") %>
<%# DataBinder.Eval(Container.DataItem, "2005-12-31") %>

</ItemTemplate>
</asp:Repeater>

==========================
This repeater will fail, however, if I have more or fewer date columns
than indicated.

So, the question is: how do I specify the number of columns at runtime?
Can I do a loop inside my repeater somehow?

I'd sure appreciate any help!

--Brent

Nov 19 '05 #3
Brent,

Don't create any columns before runtime. Then use the Repeater's
OnItemDatabound event (which fires as each row of the datasource is gone
through) to check which columns are present. Then you may dynamically add
the columns from there.

It may help you to see some code from my website that shows how to make a
datagrid's rows clickable.

Private Sub DataGrid1_ItemDataBound(ByVal sender As System.Object, ByVal e
As System.Web.UI.WebControls.DataGridItemEventArgs) Handles
DataGrid1.ItemDataBound
Try
Dim itemType As ListItemType = e.Item.ItemType

If ((itemType = ListItemType.Pager) Or (itemType = ListItemType.Header) Or
(itemType = ListItemType.Footer)) Then
Return
Else
Dim button As LinkButton = CType(e.Item.Cells(3).Controls(0), LinkButton)
e.Item.Attributes("onClick") = Page.GetPostBackClientHyperlink(button, "")
e.Item.Attributes.Add("onMouseOver",
"javascript:this.style.cursor='pointer';")
e.Item.Attributes.Add("omMouseOut",
"javascript:this.style.cursor='normal';")
End If
Catch ex As Exception
Call ProcessError("There was an error setting up the datagrid.", ex)
End Try
End Sub

Note that "e" is the datagrid's row. The repeater's items will be accessed
similarly. Sorry, but I don't have any code that uses a repeater. But I'm
hoping this will give you some ideas and some keywords to google with.
--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
"Brent" <""b b i g l e r \"@ y a h o o . c o m"> wrote in message
news:11*************@corp.supernews.com...
My SQL might generate a result like this:
Security 2005-06-30 2005-03-31 2004-12-31
IBM $65 $100 $123
(etc)

or like this:

Security 2005-06-30 2005-03-31
IBM $65 $100
(etc)

In other words, I don't know the number of columns until runtime. This
presents a problem in my repeater logic.

In the past I might do something like this:

==========================

<asp:Repeater id="dl" runat="server" EnableViewState="false">
<ItemTemplate>

<%# DataBinder.Eval(Container.DataItem, "Security")
<%# DataBinder.Eval(Container.DataItem, "2005-06-30") %>
<%# DataBinder.Eval(Container.DataItem, "2005-03-31") %>
<%# DataBinder.Eval(Container.DataItem, "2005-12-31") %>

</ItemTemplate>
</asp:Repeater>

==========================
This repeater will fail, however, if I have more or fewer date columns
than indicated.

So, the question is: how do I specify the number of columns at runtime?
Can I do a loop inside my repeater somehow?

I'd sure appreciate any help!

--Brent

Nov 19 '05 #4
Thanks for your suggestions, guys! I'll definitely look into the
onItemBound property. I think that'll fit the bill...

--Brent

Brent > wrote:
My SQL might generate a result like this:
Security 2005-06-30 2005-03-31 2004-12-31
IBM $65 $100 $123
(etc)

or like this:

Security 2005-06-30 2005-03-31
IBM $65 $100
(etc)

In other words, I don't know the number of columns until runtime. This
presents a problem in my repeater logic.

In the past I might do something like this:

==========================

<asp:Repeater id="dl" runat="server" EnableViewState="false">
<ItemTemplate>

<%# DataBinder.Eval(Container.DataItem, "Security")
<%# DataBinder.Eval(Container.DataItem, "2005-06-30") %>
<%# DataBinder.Eval(Container.DataItem, "2005-03-31") %>
<%# DataBinder.Eval(Container.DataItem, "2005-12-31") %>

</ItemTemplate>
</asp:Repeater>

==========================
This repeater will fail, however, if I have more or fewer date columns
than indicated.

So, the question is: how do I specify the number of columns at runtime?
Can I do a loop inside my repeater somehow?

I'd sure appreciate any help!

--Brent

Nov 19 '05 #5

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

Similar topics

1
1240
by: LIN | last post by:
i have an asp repeater which is bound at runtime from a dataset ...it looks like this Name Age DOB xxxx 234 7/9/07 yyyy 234 7/9/07 here all rows in the name column are hyperlink...
0
1656
by: Fraggle | last post by:
I am using PlaceHolders in a Repeater to generate a multi choice survey. I need a way of testing to see what the placeholder has been turned into at runtime, and reading out the data. The admin...
4
4123
by: MattB | last post by:
This is just a rephrased version of a question I posted earlier. I think I'm closer now, so it seemed worthy of a new (more specific) post. In my repeater I'm dynamically creating text boxes, so...
7
6307
by: gemel | last post by:
I am developing an application that uses SQL 2000 as my source of images. I have successfully created the code to load the images onto the SQL Server and also to retrieve the images into a dataset....
2
1905
by: GD | last post by:
I'd like to use a Repeater to display data coming back from a cross-tab report. Because it's a cross-tab, I generally don't know how many columns are coming back. They do follow a certain format: ...
3
437
by: GD | last post by:
I need to bind my repeater to a DataSet for which the number of columns is always different (cross-tab report). However, I need to exlude an Id column from displaying on the Repeater. As shown...
1
1685
by: Jon S via DotNetMonster.com | last post by:
Hi all In short, I have a dataset that contains 10 records and the relevant headings. All I want to do is bind this dataset to a asp.net repeater control. All the examples I've seen create...
3
3815
by: shapper | last post by:
Hello, I need to display a list of records. Each record has 3 columns: An image, a Label and a Hyperlink. I don't need paging or even raise events. All I need is to display the data as I...
11
4916
by: JJ297 | last post by:
I want to hide the Pin field below in my repeater. How do I do this? <asp:Repeater ID="Repeater1" runat="server" DataSourceID="SqlDataSource1"> <ItemTemplate> <tr> <td><font...
0
7213
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7366
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...
0
7471
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5610
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5026
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3187
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3176
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
754
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
406
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.