Solved

ASP.NET repeater control

Posted on 2012-03-28
3
533 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 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

How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

Question has a verified solution.

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

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
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.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

831 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