Solved

ASP.NET repeater control

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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.

810 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