Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Getting data out of Repeater

Status
Not open for further replies.

developer155

Programmer
Jan 21, 2004
512
US
I have a repeater control that show properties and a check box next to each. Users click check box to mark the prop they are interested in. I need some way to identify the property. Here is what I have so far, I can go and identify which box is checked, but I can find the corresponding property. Any tip is appreciated
Code---------------------------
<ItemTemplate>
<tr bgcolor="#ffcccc">
<td>
<asp:CheckBox id="PropCheck" runat="server"></asp:CheckBox></td>
<td><asp:Label ID="PropName" Runat="server"><%#DataBinder.Eval(Container.DataItem,"fPropName") %></asp:Label></td>


Here is code for it:
for (int i=0; i<PropRepeater.Items.Count; i++)
{
String isChecked = ((CheckBox) PropRepeater.Items.FindControl("PropCheck")).Checked.ToString();
if (isChecked == "True")
somevar=(Label)(PropRepeater.Items.FindControl("PropName").t.ToString();


}


thanks!!!
 
don't use .ToString, use .Text

When you are using .ToString.. you are referncing the object itself not the text of the label control
 
when I use this
somevar=(PropRepeater.Items.FindControl("PropName")

.Text is not available

it is also not available when I cast to Label type

somevar=(Label)(PropRepeater.Items.FindControl("PropName")
 
Try this code:
Code:
string somevar = ((Label)(PropRepeater.Items(i).FindControl("PropName"))).Text;
 
I tried that but it is returning empy string. Check out my code in aspx and cs:
ASPX:
<ItemTemplate>
<tr bgcolor="#ffcccc">
<td>
<asp:CheckBox id="PropCheck" runat="server"></asp:CheckBox></td>
<td><asp:Label ID="PropName" Runat="server"><%#DataBinder.Eval(Container.DataItem,"fPropName") %></asp:Label></td>
<td><%#DataBinder.Eval(Container.DataItem,"fPropAddr1") %></td>
<td><%#DataBinder.Eval(Container.DataItem,"fPropCity") %></td>

</tr>

And here is the code behind:
for (int i=0; i<PropRepeater.Items.Count; i++)
{
String isChecked = ((CheckBox) PropRepeater.Items.FindControl("PropCheck")).Checked.ToString();
if (isChecked == "True")
somevar = ((Label)(PropRepeater.Items.FindControl("PropName"))).Text;



}

See anything wrong?

Thanks for all your help!!!
 
JBenson, thansk for all your help, I finally figured it out
Here is what I needed to change in aspx side
<asp:Label id="PropName" Runat="server" text=<%#DataBinder.Eval(Container.DataItem,"fPropName")%>>

added attribute text to the label, I did not have it before

thanks again for pointing me to the right direction
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top