Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

ASP.NET repeater control

Posted on 2012-03-28
3
Medium Priority
?
542 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 2000 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 20

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

Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Hello there! As a developer I have modified and refactored the unit tests which was written by fellow developers in the past. On the course, I have gone through various misconceptions and technical challenges when it comes to implementation. I would…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Suggested Courses

824 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