By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,247 Members | 1,287 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,247 IT Pros & Developers. It's quick & easy.

Repeater + Getting Column Names at Runtime

P: n/a
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
Share this Question
Share on Google+
4 Replies


P: n/a
"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

P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.