Solved

ASP.NET repeater control

Posted on 2012-03-28
3
531 Views
Last Modified: 2012-03-28
I have a repeater control

 <asp:Repeater ID="rptFiles" runat="server" onitemcommand="rptFiles_ItemCommand">
    <HeaderTemplate>
        <strong>Downloadable Files:</strong><br />
    </HeaderTemplate>
    <ItemTemplate>
        <asp:LinkButton ID="lbDocs" runat="server"
            Text="<%# ((Files)Container.DataItem).FileName %>" /><br />
    </ItemTemplate>
    <FooterTemplate>
    </FooterTemplate>
</asp:Repeater>

I want to know if it is possible to have a text and a value similar to a dropdown box?  I need to display one value but actually capture another value on the click of the repeater.

Thanks
0
Comment
Question by:CipherIS
3 Comments
 
LVL 20

Accepted Solution

by:
BuggyCoder earned 500 total points
ID: 37777735
use a hidden field and bind another value to it
<ItemTemplate>
        <asp:LinkButton ID="lbDocs" runat="server"
            Text="<%# ((Files)Container.DataItem).FileName %>" /><br />
        <asp:HiddenField Id="hdValue" runat="server" value="<%# ((Files)Container.DataItem).OtherValue" />
    </ItemTemplate>

Now you can access this value from your code behind in repeater's itemcommand event if you have button in repeater as well....
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.repeater.itemcommand.aspx
0
 
LVL 19

Expert Comment

by:Daniel Van Der Werken
ID: 37777773
I think BuggyCoder's solution would work fine, but I just thought of another possibility I thought I'd share. If you have knowledge beforehand  (and you don't need this other value text on the page for any reason )on what the value combinations are going to be repeater-text and "other value" text, you can always setup a HashTable and store the OtherValue as the Value and the Repeater Text as the key.

So, set up the HashTable and then when the user clicks the repeater, grab that text and run it though the hashtable  to get the value you want.
0
 
LVL 1

Author Comment

by:CipherIS
ID: 37778233
@BuggyCoder

Thanks for the solution.  That works.  How do I get the selected item?  Below gives me the display name.  The File Name is in the hidden field.

 string sSelected = ((System.Web.UI.WebControls.LinkButton)(e.CommandSource)).Text;
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now