fwsteal
asked on
c# 2.0 how to append to a repeater control
How do I append to two hyperlink controls within a repeater?
My error:
Error 1 'System.Web.UI.WebControls .Repeater' does not contain a definition for 'items'
--------------------------
<table width="100%" border="0" cellspacing="5" cellpadding="5">
<tr>
<asp:Repeater ID="Repeater1" runat="server">
<ItemTemplate>
<td>
<asp:HyperLink
ID="HyperLink1"
Runat="server"
Text='<%# Eval("Name") %>'
NavigateUrl='<%# "../Item.aspx?DepartmentID =" + Eval("departmentId") + "&CategoryID=" + Eval("categoryId") + "&ProductID=" + Eval("ProductID")%>'
ImageUrl='<%# "../images/productimages/" + Eval("Image1FileName") %>'
ToolTip='<%# Eval("Name") %>'
CssClass='<%# Eval("ProductID").ToString () == Request.QueryString["Produ ctID"] ? "ProductSelected" : "ProductUnselected" %>'
>
</asp:HyperLink>
<br />
<asp:HyperLink ID="HyperLinkName" runat="server" Text='<%# DataBinder.Eval(Container. DataItem, "Name")%>' NavigateUrl='<%# "../Item.aspx?DepartmentID =" + Eval("departmentId") + "&CategoryID=" + Eval("categoryId") + "&ProductID=" + Eval("ProductID") %>' >
</asp:HyperLink>
<br />
<%# DataBinder.Eval(Container. DataItem, "Price", "{0:c}")%>
<br />
</td>
</ItemTemplate>
<HeaderTemplate>
<strong>
Products</strong>
</HeaderTemplate>
</asp:Repeater>
</tr>
</table>
--------------------------
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
string categoryId = Request.QueryString["Categ oryID"];
string ep = Request.QueryString["ep"];
if (categoryId != null)
{
Repeater1.DataSource = CatalogAccess.GetAllProduc tsInCatego ry(categor yId, ep);
Repeater1.DataBind();
Repeater1.items(0).FindCon trol("Hype rLink1") += "&ep=" + ep; //error
Repeater1.items(0).FindCon trol("Hype rLinkName" ) += "&ep=" + ep; //error
}
}
}
-------------------------- --
My error:
Error 1 'System.Web.UI.WebControls
--------------------------
<table width="100%" border="0" cellspacing="5" cellpadding="5">
<tr>
<asp:Repeater ID="Repeater1" runat="server">
<ItemTemplate>
<td>
<asp:HyperLink
ID="HyperLink1"
Runat="server"
Text='<%# Eval("Name") %>'
NavigateUrl='<%# "../Item.aspx?DepartmentID
ImageUrl='<%# "../images/productimages/"
ToolTip='<%# Eval("Name") %>'
CssClass='<%# Eval("ProductID").ToString
>
</asp:HyperLink>
<br />
<asp:HyperLink ID="HyperLinkName" runat="server" Text='<%# DataBinder.Eval(Container.
</asp:HyperLink>
<br />
<%# DataBinder.Eval(Container.
<br />
</td>
</ItemTemplate>
<HeaderTemplate>
<strong>
Products</strong>
</HeaderTemplate>
</asp:Repeater>
</tr>
</table>
--------------------------
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
string categoryId = Request.QueryString["Categ
string ep = Request.QueryString["ep"];
if (categoryId != null)
{
Repeater1.DataSource = CatalogAccess.GetAllProduc
Repeater1.DataBind();
Repeater1.items(0).FindCon
Repeater1.items(0).FindCon
}
}
}
--------------------------
ASKER
I'm trying to do this to all the hyperlink items in the repeater; I'm not sure how to do that.
ASKER
this?
<asp:Repeater ID="Repeater1" runat="server" OnDataBinding="AppendEP">
protected void AppendEP(object sender, System.Web.UI.WebControls. RepeaterIt emEventArg s e)
{
string ep = Request.QueryString["ep"];
HyperLink lnk1 = (HyperLink)Repeater1.Items [0].FindCo ntrol("Hyp erlink1");
lnk1.NavigateUrl += "&ep=" + ep;
HyperLink lnk2 = (HyperLink)Repeater1.Items [0].FindCo ntrol("Hyp erLinkName ");
lnk2.NavigateUrl += "&ep=" + ep;
}
<asp:Repeater ID="Repeater1" runat="server" OnDataBinding="AppendEP">
protected void AppendEP(object sender, System.Web.UI.WebControls.
{
string ep = Request.QueryString["ep"];
HyperLink lnk1 = (HyperLink)Repeater1.Items
lnk1.NavigateUrl += "&ep=" + ep;
HyperLink lnk2 = (HyperLink)Repeater1.Items
lnk2.NavigateUrl += "&ep=" + ep;
}
ASKER
changed it sort of:
<asp:Repeater ID="Repeater1" runat="server" OnItemDataBound="Repeater1 _ItemDataB ound">
protected void Repeater1_ItemDataBound(ob ject sender, RepeaterItemEventArgs e)
{
string ep = Request.QueryString["ep"];
HyperLink lnk1 = (HyperLink)Repeater1.Items [0].FindCo ntrol("Hyp erlink1"); //errors
lnk1.NavigateUrl += "&ep=" + ep;
HyperLink lnk2 = (HyperLink)Repeater1.Items [0].FindCo ntrol("Hyp erLinkName "); //errors
lnk2.NavigateUrl += "&ep=" + ep;
}
error: Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index
<asp:Repeater ID="Repeater1" runat="server" OnItemDataBound="Repeater1
protected void Repeater1_ItemDataBound(ob
{
string ep = Request.QueryString["ep"];
HyperLink lnk1 = (HyperLink)Repeater1.Items
lnk1.NavigateUrl += "&ep=" + ep;
HyperLink lnk2 = (HyperLink)Repeater1.Items
lnk2.NavigateUrl += "&ep=" + ep;
}
error: Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
2nd): FindControl returns a type of Control, so you have tell it what type of control. Here is an example (C#):
HyperLink lnk1 = (HyperLink)Repeater1.Items
lnk1.NavigateUrl += "&ep=" + ep;
HyperLink lnk2 = (HyperLink)Repeater1.Items
lnk2.NavigateUrl += "&ep=" + ep;
I am not sure if you are just doing this to Item 0, but if you want it performed on all items, you need to have a Repeater1_ItemDataBound(ob