×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Getting data out of Repeater

Getting data out of Repeater

Getting data out of Repeater

(OP)
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[i].FindControl("PropCheck")).Checked.ToString();
                    if (isChecked == "True")
                        somevar=(Label)(PropRepeater.Items[i].FindControl("PropName").t.ToString();

                    
                }


thanks!!!

RE: Getting data out of Repeater

do you get an error?  what happens?

RE: Getting data out of Repeater

(OP)
I do not get any value, empty string.

thanks

RE: Getting data out of Repeater

don't use .ToString, use .Text

When you are using .ToString.. you are referncing the object itself not the text of the label control

RE: Getting data out of Repeater

(OP)
when I use this
somevar=(PropRepeater.Items[i].FindControl("PropName")

.Text is not available

it is also not available when I cast to Label type

somevar=(Label)(PropRepeater.Items[i].FindControl("PropName")

RE: Getting data out of Repeater

Try this code:

CODE

string somevar = ((Label)(PropRepeater.Items(i).FindControl("PropName"))).Text;

RE: Getting data out of Repeater

(OP)
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[i].FindControl("PropCheck")).Checked.ToString();
                    if (isChecked == "True")
                        somevar = ((Label)(PropRepeater.Items[i].FindControl("PropName"))).Text;
                        

                    
                }

See anything wrong?

Thanks for all your help!!!

RE: Getting data out of Repeater

(OP)
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

RE: Getting data out of Repeater

Ohh cool.. glad you got it working  :)

Jim

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login


Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close