Repeater question

  • Thread starter Øyvind Isaksen
  • Start date
Ø

Øyvind Isaksen

I have a reperater that returns 5 last articles from a given category.
In the bottom of the list (in the FooterTemplate) I want to make a link to
a page that list all articles in this category. How can I get the Category
ID from the repeater???

----------------------------------------------
This is the ASPX.VB file (codebehind-code):
----------------------------------------------
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim SQL As String = "select top 5 artID,catID,title,regdate from
tblArticle where active='1' and catID=@catID"
Dim conn As New SqlConnection(variables.ConnString)
Dim cmd As New SqlCommand(SQL, conn)

Dim parameter1 As New SqlParameter("@catID", variables.newsID)
'variables.newsID is a class that returns the categoryID
cmd.Parameters.Add(parameter1)

cmd.Connection.Open()

Dim dr As SqlDataReader = cmd.ExecuteReader
Me.rptNewsList.DataSource = dr
Me.rptNewsList.DataBind()

cmd.Connection.Close()
cmd.Dispose()
conn.Dispose()
End Sub


------------------------------
This is the ASPX-file:
------------------------------
<asp:Repeater id="rptNewsList" runat="server">

<HeaderTemplate>
News
</HeaderTemplate>

<ItemTemplate>
<a
href="detail.aspx?cat=<%#container.dataitem("catID")%>&artID=<%#container.dataitem("artID")%>"><%#container.dataitem("title")%></a>
</ItemTemplate>

<SeparatorTemplate>
<br>
</SeparatorTemplate>

<FooterTemplate>
[<a href="/ld/default.aspx?catID=HERE-I-NEED-THE-CATEGORY-ID">Show
all</a>]
</FooterTemplate>

</asp:Repeater>
 
E

Eliyahu Goldin

Handle ItemDataBound event. In the event you have access to the repeater
items. I can read the category id and save it in a variable. The same event
will be fired for the footer. You can tell the type of the item by the
ItemType property. When it is the footer, get the category id from the
variable and stick it inside the footer.

Eliyahu

Øyvind Isaksen said:
I have a reperater that returns 5 last articles from a given category.
In the bottom of the list (in the FooterTemplate) I want to make a link to
a page that list all articles in this category. How can I get the Category
ID from the repeater???

----------------------------------------------
This is the ASPX.VB file (codebehind-code):
----------------------------------------------
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim SQL As String = "select top 5 artID,catID,title,regdate from
tblArticle where active='1' and catID=@catID"
Dim conn As New SqlConnection(variables.ConnString)
Dim cmd As New SqlCommand(SQL, conn)

Dim parameter1 As New SqlParameter("@catID", variables.newsID)
'variables.newsID is a class that returns the categoryID
cmd.Parameters.Add(parameter1)

cmd.Connection.Open()

Dim dr As SqlDataReader = cmd.ExecuteReader
Me.rptNewsList.DataSource = dr
Me.rptNewsList.DataBind()

cmd.Connection.Close()
cmd.Dispose()
conn.Dispose()
End Sub


------------------------------
This is the ASPX-file:
------------------------------
<asp:Repeater id="rptNewsList" runat="server">

<HeaderTemplate>
News
</HeaderTemplate>

<ItemTemplate>
<a
href="detail.aspx?cat= said:
</ItemTemplate>

<SeparatorTemplate>
<br>
</SeparatorTemplate>

<FooterTemplate>
[<a href="/ld/default.aspx?catID=HERE-I-NEED-THE-CATEGORY-ID">Show
all</a>]
</FooterTemplate>

</asp:Repeater>
 
Ø

Øyvind Isaksen

Ok, this means that I write something like this:

_________________________
Private Sub rptNewsList_ItemDataBound(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.RepeaterItemEventArgs) Handles
rptNewsList.ItemDataBound

End Sub
_____________________________

But, what do I write inside the "rptNewsList_ItemDataBound"procedure so I
can get the category ID in the FooterTemplate? And, what do I write in the
FooterTemplate?

Thanks alot for your reply!!!!!!




Eliyahu Goldin said:
Handle ItemDataBound event. In the event you have access to the repeater
items. I can read the category id and save it in a variable. The same
event
will be fired for the footer. You can tell the type of the item by the
ItemType property. When it is the footer, get the category id from the
variable and stick it inside the footer.

Eliyahu

Øyvind Isaksen said:
I have a reperater that returns 5 last articles from a given category.
In the bottom of the list (in the FooterTemplate) I want to make a link to
a page that list all articles in this category. How can I get the
Category
ID from the repeater???

----------------------------------------------
This is the ASPX.VB file (codebehind-code):
----------------------------------------------
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim SQL As String = "select top 5 artID,catID,title,regdate from
tblArticle where active='1' and catID=@catID"
Dim conn As New SqlConnection(variables.ConnString)
Dim cmd As New SqlCommand(SQL, conn)

Dim parameter1 As New SqlParameter("@catID", variables.newsID)
'variables.newsID is a class that returns the categoryID
cmd.Parameters.Add(parameter1)

cmd.Connection.Open()

Dim dr As SqlDataReader = cmd.ExecuteReader
Me.rptNewsList.DataSource = dr
Me.rptNewsList.DataBind()

cmd.Connection.Close()
cmd.Dispose()
conn.Dispose()
End Sub


------------------------------
This is the ASPX-file:
------------------------------
<asp:Repeater id="rptNewsList" runat="server">

<HeaderTemplate>
News
</HeaderTemplate>

<ItemTemplate>
<a
href="detail.aspx?cat= said:
</ItemTemplate>

<SeparatorTemplate>
<br>
</SeparatorTemplate>

<FooterTemplate>
[<a href="/ld/default.aspx?catID=HERE-I-NEED-THE-CATEGORY-ID">Show
all</a>]
</FooterTemplate>

</asp:Repeater>
 
P

Patrick.O.Ige

Do something like :-

public void itemDB(object sender,DataGridItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Footer)
{
Label lblCatID = ((Label)(e.Item.FindControl("CatID")));

}

}
Hope that helps
Patrick

Øyvind Isaksen said:
Ok, this means that I write something like this:

_________________________
Private Sub rptNewsList_ItemDataBound(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.RepeaterItemEventArgs) Handles
rptNewsList.ItemDataBound

End Sub
_____________________________

But, what do I write inside the "rptNewsList_ItemDataBound"procedure so I
can get the category ID in the FooterTemplate? And, what do I write in the
FooterTemplate?

Thanks alot for your reply!!!!!!




Eliyahu Goldin said:
Handle ItemDataBound event. In the event you have access to the repeater
items. I can read the category id and save it in a variable. The same
event
will be fired for the footer. You can tell the type of the item by the
ItemType property. When it is the footer, get the category id from the
variable and stick it inside the footer.

Eliyahu

link
to
href="detail.aspx?cat= said:
taitem("artID")%>"> said:
</ItemTemplate>

<SeparatorTemplate>
<br>
</SeparatorTemplate>

<FooterTemplate>
[<a href="/ld/default.aspx?catID=HERE-I-NEED-THE-CATEGORY-ID">Show
all</a>]
</FooterTemplate>

</asp:Repeater>
 

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,770
Messages
2,569,583
Members
45,074
Latest member
StanleyFra

Latest Threads

Top