Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • ds 191 posts 223 karma points
    Aug 15, 2011 @ 14:36
    ds
    0

    How to prevalue as string via codebehind?

    I try to get the string from prevalue and display text in griedview. How can I do it?

                List lst = new List();            
    var members = Member.GetAll;

    foreach (Member member in members)
    {
    lst.Add(member.getProperty("member_CompanyName").Value.ToString());
    }

    GridView1.DataSource = lst;
    GridView1.DataBind();

     

     

  • ds 191 posts 223 karma points
    Aug 15, 2011 @ 15:06
    ds
    0

    I tried something like that but it still shows ids

                List lst = new List();            
    var members = Member.GetAll;

    foreach (Member member in members)
    {
    lst.Add(member.getProperty("member_CompanyName").Value.ToString());
    var mp = member.getProperty("member_Province").Value.ToString();
    foreach(var id in mp.Split(','))
    {
    lst.Add(id);
    //Response.Write(id);
    }
    }

    GridView1.DataSource = lst;
    GridView1.DataBind();
  • andy_rose 91 posts 117 karma points
    Aug 15, 2011 @ 17:03
    andy_rose
    0

    If you know the umbraco id of the datatype you are using to get prevalues from you can use umbraco.library method GetPrevalues(int dataTypeId):

    var preValues = umbraco.library.GetPrevalues(1234);

    Alternatively for a specific prevalue you can use the GetPreValueAsString(int id) method:

    var preValueString = umbraco.library.GetPreValueAsString(1234);

    Looking at your above code you could try something like:

    foreach(Member member in members)
               
    {
                    var preVal = (int)member.getProperty("member_CompanyName").Value;                 lst.Add(umbraco.library.GetPreValueAsString(preVal));
               
    }

     

  • ds 191 posts 223 karma points
    Aug 16, 2011 @ 20:16
    ds
    0

    After trying your suggestion andy, I get 

    Specified cast is not valid.

  • andy_rose 91 posts 117 karma points
    Aug 17, 2011 @ 10:49
    andy_rose
    0

    Sorry, I think the Value property object that represents the id is a string. Try the following:

    var preVal =Convert.ToInt32(member.getProperty("member_CompanyName").Value);

     

Please Sign in or register to post replies

Write your reply to:

Draft