Solved

ASP.NET repeater control

Posted on 2012-03-28
3
538 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

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.
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 video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

617 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