Getting the text from listview

5 posts, 0 answers
  1. Dana
    Dana avatar
    6 posts
    Member since:
    Feb 2011

    Posted 29 Jan 2014 Link to this post

    Hi,

    I'm simply looking to return the text from a listview where I have an id for the key field and a name field which is what is displayed.  I thought this would be relatively simple but keep failing. 

    Also I can't seem to find a way to get the first item selected by default when the page loads.

    I thought for sue I could find something like this in the forums but came up empty.

    Thanks
  2. Dana
    Dana avatar
    6 posts
    Member since:
    Feb 2011

    Posted 30 Jan 2014 in reply to Dana Link to this post

    Was able to answer the first part by sifting through the example code.  Found this:

              RadListView1.SelectedItems[0].ExtractValues(values);
              string make = values["Make"].ToString();
              string model = values["Model"].ToString();

    but things must have changed since when I tried to do it I couldn't find ExtractValues in the intellisense.  But this worked:

    string temp = RadListView1.SelectedItems[0].Text

    Certainly simpler!  Now if I could only figure out how to programmatically select the first item in the list box.  I found some suggestions from other posts that so far haven't worked for me. 
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Eyup
    Admin
    Eyup avatar
    3005 posts

    Posted 03 Feb 2014 Link to this post

    Hello Dana,

    I have created a sample RadListView web site to demonstrate different approaches to achieve the requested functionality. Please run the attached application and let me know if it helps you.

    Regards,
    Eyup
    Telerik
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the UI for ASP.NET AJAX, subscribe to the blog feed now.
  5. Dana
    Dana avatar
    6 posts
    Member since:
    Feb 2011

    Posted 06 Feb 2014 in reply to Eyup Link to this post

    Forgive me, but I tried to put it all into a solution and am clearly missing something because it didn't work.

    Incidentally to clarify the issue I'm having with the listview, it appears to always be behind by one click.  In other words, even though I see the item in the listview, the text box that I have linked to it by setting its value to the first item in the listview is apparently updated after the listview completes.  In fact, the first time through always generated an error.  Here's the code:

        protected void RadListBox_Depts_SelectedIndexChanged(object sender, EventArgs e)
        {
            RadListBox_UserName.SelectedIndex = 0;
            if (RadListBox_UserName.SelectedIndex !=-1)
            {
                labelUserName.Text = RadListBox_UserName.SelectedItems[0].Text;
            }

    I've tried all the other methods and still end up one click behind.  
  6. Eyup
    Admin
    Eyup avatar
    3005 posts

    Posted 11 Feb 2014 Link to this post

    Hi Dana,

    Do you use RadListView or RadListBox? Please note that they are entirely separate controls.

    I suppose you are using RadListView. In that case, the suggested approaches in the provided web site should work correctly. Can you please verify that you have run the web site and it works as expected?

    It would be great if you modify the RadListViewSelectionFirstItem.zip to demonstrate the issue and open a support ticket to send it back to us, along with detailed steps and a sample video. Thus, we will be able to further debug and analyze the project and suggest a proper solution.

    Regards,
    Eyup
    Telerik
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the UI for ASP.NET AJAX, subscribe to the blog feed now.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017