I have a weird problem with a repeater control. I want to place literal controls inside the repeater control and then set the text of that literal from codebehind, but when I try to do that VS 2008 tell me that the literal control is not declared, but if
I place it outside the repeater control it works. What can be causing this?
You want to add items to a reapeater dynamically from code behind, this piece of code should help you.
Please write this code in your repeaters itemdatabound event.
dim item as new literalcontrol()
item.text=e.item.dataItem("columnname")
rpt.controls.add(item)
modig
Member
475 Points
420 Posts
literal inside repeater is not declared
May 14, 2008 07:23 AM|LINK
Hi
I have a weird problem with a repeater control. I want to place literal controls inside the repeater control and then set the text of that literal from codebehind, but when I try to do that VS 2008 tell me that the literal control is not declared, but if I place it outside the repeater control it works. What can be causing this?
yeotumitsu@s...
Contributor
4907 Points
836 Posts
Re: literal inside repeater is not declared
May 14, 2008 07:29 AM|LINK
You must be missing something. Check this code -
================================================
<asp:Repeater ID="rptTeamTracker" runat="server" OnItemDataBound="rptListTracker_ItemDataBound">
<ItemTemplate>
<div class="text">
<ul>
<li class="main">
<a href="TeamProfile.aspx?TeamID=<%#Eval("TeamId") %>"><%#Eval("TeamName")%></a>
</li></ul>
<ul><li>Last Match</li></ul>
<ul>
<li><div><asp:Literal ID="Label1" runat="server" Text='<%#Eval("lastMatchInfo") %>'></asp:Literal></div></li>
</ul>
<ul><li>Next Match</li></ul>
<ul>
<li><asp:Literal ID="lbltschedule" runat="server" Text='<%#Eval("nextMatchDate") %>'></asp:Literal></li>
</ul>
</li>
</ul>
</div>
<asp:Image ID="imgteam" width="46" alt="" runat="server" />
</ItemTemplate>
</asp:Repeater>
===================================================
-Manas
=======================================
If this post is useful to you, please mark it as answer.
modig
Member
475 Points
420 Posts
Re: literal inside repeater is not declared
May 14, 2008 07:45 AM|LINK
Hi
This is all to weird, your code does not work either. If I try this in codebehind...
Label1.Text = "test", then I get a "label1 is not declared" error in VS 2008.
dinesh_sp
Contributor
2272 Points
413 Posts
Re: literal inside repeater is not declared
May 14, 2008 08:01 AM|LINK
Hi ModiG,
You want to add items to a reapeater dynamically from code behind, this piece of code should help you.
Please write this code in your repeaters itemdatabound event.
dim item as new literalcontrol()
item.text=e.item.dataItem("columnname")
rpt.controls.add(item)
This would help you.
modig
Member
475 Points
420 Posts
Re: literal inside repeater is not declared
May 14, 2008 08:13 AM|LINK
What I try to do is to have literal inside a href link like this..
<a href="test.aspx?T=<asp:Literal ID="Lit1" runat="server" />&S=<asp:Literal ID="Lit2" runat="server" />">my link</a>
and then set the Lit1 and lit2 text values from codebehind.
koolprogramm...
Member
328 Points
160 Posts
Re: literal inside repeater is not declared
May 14, 2008 08:15 AM|LINK
when you use controls within a repeater u have to declare them in the databound of the repeater to access them..
Vince Xu - M...
All-Star
80367 Points
6801 Posts
Re: literal inside repeater is not declared
May 16, 2008 05:21 AM|LINK
Hi,
You can use FindControl to get the control in Repeater.
foreach (RepeaterItem Item in Repeater1.Items)
{
TextBox TextBoxEntry = (TextBox)Item.FindControl("TextBox1");
string valueNew = TextBoxEntry.Text;
Response.Write(valueNew);
}
You can also use Repeater1.ItemDataBound event to set control in each item.
Hope it helps.