Combine many Repeaters into 1

R

Roy

No errors here, I'm just looking for ways to make my code more
efficient. As the subject line suggests, I have a LOT of repeaters on a
certain page. They are visible or hidden depending on user actions and
are dispersed about the page via an "image map" style of GUI. The code
behind (and associated aspx) is below, you'll note that they all pull
from the same table and all virtually identical except for ID's and what
data they pull. How can I make this more efficient? Can I combine all
the repeaters into one and pull via a relation some-how? If so, how
would I do this?
THANKS

*****Code behind*****

Dim mycom1 As New SqlCommand("SELECT b.site, count(*)as cnt from cm_last
a right join theater b on a.loc_cd = b.geo_code where b.area = 'jar'
group by b.site", myconn)
Dim newadp1 As New SqlDataAdapter(mycom1)
Dim newds1 As New DataSet
newadp1.Fill(newds1, "one")
notesgrid1.DataSource = newds1.Tables("one").DefaultView
notesgrid1.DataBind()

Dim mycom2 As New SqlCommand("SELECT b.site, count(*)as cnt from cm_last
a right join theater b on a.loc_cd = b.geo_code where b.area = 'ncn'
group by b.site", myconn)
Dim newadp2 As New SqlDataAdapter(mycom2)
Dim newds2 As New DataSet
newadp2.Fill(newds2, "one")
notesgrid2.DataSource = newds2.Tables("one").DefaultView
notesgrid2.DataBind()

Dim mycom3 As New SqlCommand("SELECT b.site, count(*)as cnt from cm_last
a right join theater b on a.loc_cd = b.geo_code where b.area = 'trz'
group by b.site", myconn)
Dim newadp3 As New SqlDataAdapter(mycom3)
Dim newds3 As New DataSet
newadp3.Fill(newds3, "one")
notesgrid3.DataSource = newds3.Tables("one").DefaultView
notesgrid3.DataBind()

Dim mycom4 As New SqlCommand("SELECT b.site, count(*)as cnt from cm_last
a right join theater b on a.loc_cd = b.geo_code where b.area = 'lb1'
group by b.site", myconn)
Dim newadp4 As New SqlDataAdapter(mycom4)
Dim newds4 As New DataSet
newadp4.Fill(newds4, "one")
notesgrid4.DataSource = newds4.Tables("one").DefaultView
notesgrid4.DataBind()

Dim mycom5 As New SqlCommand("SELECT b.site, count(*)as cnt from cm_last
a right join theater b on a.loc_cd = b.geo_code where b.area = 'lrd'
group by b.site", myconn)
Dim newadp5 As New SqlDataAdapter(mycom5)
Dim newds5 As New DataSet
newadp5.Fill(newds5, "one")
notesgrid5.DataSource = newds5.Tables("one").DefaultView
notesgrid5.DataBind()



*****ASPX code*****

<div ID="note1" class="note">
<asp:repeater id="notesgrid1" Runat="server">
<HeaderTemplate>
Area 1
</HeaderTemplate>
<ItemTemplate>
<%#Container.DataItem("site")%> (<%# container.dataitem("cnt")%>)
</ItemTemplate>
<SeparatorTemplate><br></SeparatorTemplate>
</asp:repeater>
</div>

<div ID="note2" class="note">
<asp:repeater id="notesgrid2" Runat="server">
<HeaderTemplate>
Area 2
</HeaderTemplate>
<ItemTemplate>
<%#Container.DataItem("site")%> (<%# container.dataitem("cnt")%>)
</ItemTemplate>
<SeparatorTemplate>
<br>
</SeparatorTemplate>
</asp:repeater>
</div>

<div ID="note3" class="note">
<asp:repeater id="notesgrid3" Runat="server">
<HeaderTemplate>
Area 3
</HeaderTemplate>
<ItemTemplate>
<%#Container.DataItem("site")%> (<%# container.dataitem("cnt")%>)
</ItemTemplate>
<SeparatorTemplate>
<br>
</SeparatorTemplate>
</asp:repeater>
</div>

<div ID="note4" class="note">
<asp:repeater id="notesgrid4" Runat="server">
<HeaderTemplate>
Area 4
</HeaderTemplate>
<ItemTemplate>
<%#Container.DataItem("site")%> (<%# container.dataitem("cnt")%>)
</ItemTemplate>
<SeparatorTemplate>
<br>
</SeparatorTemplate>
</asp:repeater>
</div>

<div ID="note5" class="note">
<asp:repeater id="notesgrid5" Runat="server">
<HeaderTemplate>
Area 5
</HeaderTemplate>
<ItemTemplate>
<%#Container.DataItem("site")%> (<%# container.dataitem("cnt")%>)
</ItemTemplate>
<SeparatorTemplate>
<br>
</SeparatorTemplate>
</asp:repeater>
</div>
 
R

Roy

Quick repost since no answers first time:
Anyone have any thoughts on this?
Thanks much.


From: Roy

No errors here, I'm just looking for ways to make my code more
efficient. As the subject line suggests, I have a LOT of repeaters on a
certain page. They are visible or hidden depending on user actions and
are dispersed about the page via an "image map" style of GUI. The code
behind (and associated aspx) is below, you'll note that they all pull
from the same table and all virtually identical except for ID's and what
data they pull. How can I make this more efficient? Can I combine all
the repeaters into one and pull via a relation some-how? If so, how
would I do this?
THANKS

*****Code behind*****

Dim mycom1 As New SqlCommand("SELECT b.site, count(*)as cnt from cm_last
a right join theater b on a.loc_cd = b.geo_code where b.area = 'jar'
group by b.site", myconn)
Dim newadp1 As New SqlDataAdapter(mycom1)
Dim newds1 As New DataSet
newadp1.Fill(newds1, "one")
notesgrid1.DataSource = newds1.Tables("one").DefaultView
notesgrid1.DataBind()

Dim mycom2 As New SqlCommand("SELECT b.site, count(*)as cnt from cm_last
a right join theater b on a.loc_cd = b.geo_code where b.area = 'ncn'
group by b.site", myconn)
Dim newadp2 As New SqlDataAdapter(mycom2)
Dim newds2 As New DataSet
newadp2.Fill(newds2, "one")
notesgrid2.DataSource = newds2.Tables("one").DefaultView
notesgrid2.DataBind()

Dim mycom3 As New SqlCommand("SELECT b.site, count(*)as cnt from cm_last
a right join theater b on a.loc_cd = b.geo_code where b.area = 'trz'
group by b.site", myconn)
Dim newadp3 As New SqlDataAdapter(mycom3)
Dim newds3 As New DataSet
newadp3.Fill(newds3, "one")
notesgrid3.DataSource = newds3.Tables("one").DefaultView
notesgrid3.DataBind()

Dim mycom4 As New SqlCommand("SELECT b.site, count(*)as cnt from cm_last
a right join theater b on a.loc_cd = b.geo_code where b.area = 'lb1'
group by b.site", myconn)
Dim newadp4 As New SqlDataAdapter(mycom4)
Dim newds4 As New DataSet
newadp4.Fill(newds4, "one")
notesgrid4.DataSource = newds4.Tables("one").DefaultView
notesgrid4.DataBind()

Dim mycom5 As New SqlCommand("SELECT b.site, count(*)as cnt from cm_last
a right join theater b on a.loc_cd = b.geo_code where b.area = 'lrd'
group by b.site", myconn)
Dim newadp5 As New SqlDataAdapter(mycom5)
Dim newds5 As New DataSet
newadp5.Fill(newds5, "one")
notesgrid5.DataSource = newds5.Tables("one").DefaultView
notesgrid5.DataBind()



*****ASPX code*****

<div ID="note1" class="note">
<asp:repeater id="notesgrid1" Runat="server">
<HeaderTemplate>
Area 1
</HeaderTemplate>
<ItemTemplate>
<%#Container.DataItem("site")%> (<%# container.dataitem("cnt")%>)
</ItemTemplate>
<SeparatorTemplate><br></SeparatorTemplate>
</asp:repeater>
</div>

<div ID="note2" class="note">
<asp:repeater id="notesgrid2" Runat="server">
<HeaderTemplate>
Area 2
</HeaderTemplate>
<ItemTemplate>
<%#Container.DataItem("site")%> (<%# container.dataitem("cnt")%>)
</ItemTemplate>
<SeparatorTemplate>
<br>
</SeparatorTemplate>
</asp:repeater>
</div>

<div ID="note3" class="note">
<asp:repeater id="notesgrid3" Runat="server">
<HeaderTemplate>
Area 3
</HeaderTemplate>
<ItemTemplate>
<%#Container.DataItem("site")%> (<%# container.dataitem("cnt")%>)
</ItemTemplate>
<SeparatorTemplate>
<br>
</SeparatorTemplate>
</asp:repeater>
</div>

<div ID="note4" class="note">
<asp:repeater id="notesgrid4" Runat="server">
<HeaderTemplate>
Area 4
</HeaderTemplate>
<ItemTemplate>
<%#Container.DataItem("site")%> (<%# container.dataitem("cnt")%>)
</ItemTemplate>
<SeparatorTemplate>
<br>
</SeparatorTemplate>
</asp:repeater>
</div>

<div ID="note5" class="note">
<asp:repeater id="notesgrid5" Runat="server">
<HeaderTemplate>
Area 5
</HeaderTemplate>
<ItemTemplate>
<%#Container.DataItem("site")%> (<%# container.dataitem("cnt")%>)
</ItemTemplate>
<SeparatorTemplate>
<br>
</SeparatorTemplate>
</asp:repeater>
</div>
 

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,774
Messages
2,569,596
Members
45,135
Latest member
VeronaShap
Top