2 Datagrid columns questions

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Mark B

    2 Datagrid columns questions

    I have a Datagrid working fine, outputting:

    Group
    Most Popular Product Code
    --------
    -------------------------------

    Earth.New Zealand
    32
    Earth.New Zealand
    32
    Earth.New Zealand.Aucklan d
    32
    Earth.New Zealand.Aucklan d
    32
    Earth.New Zealand.Aucklan d.Auckland
    7
    Earth.New Zealand.Aucklan d.Auckland.Parn ell
    7
    Earth.New Zealand.Aucklan d.Henderson
    10024
    Earth.New Zealand.Aucklan d.Henderson.New Account
    10024
    Earth.United States
    32
    Earth.United States.Texas
    32


    Now I want to do these 2 things:

    1) Have clickable hyperlinks on each sub-group and not the periods e.g. for
    the last entry above (Earth.United States.Texas):

    <a href="http://www.mysite.com/showgroups/?GroupName=Eart h">Earth</a>.<a
    href="http://www.mysite.com/showgroups/?GroupName=Eart h.United
    States">United States</a>.<a
    href="http://www.mysite.com/showgroups/?GroupName=Eart h.United
    States.Texas">T exas</a>

    I still want people to be able to sort the column as displayed though.


    2) Rather than display the Most Popular Product Code (SQL int), I want the
    result of the function fConvertCodeToP roductTitle(lng ProductID as Long) as
    String. I still want people to be able to sort by the long integer value
    though -- even though I don't want it displayed for the column.

    How can I do this with the Datagrid control (Visual Web Developer 2008
    Express)?

    TIA

  • Munna

    #2
    Re: 2 Datagrid columns questions

    Hi

    on item data bound change your output as you want...



    Best of luck

    Munna


    Comment

    • Steven Cheng [MSFT]

      #3
      RE: 2 Datagrid columns questions

      Hi Mark,

      For your scenario, since the string transforming logic is not that
      simple(you need to format both the display string and the url string ), I
      think you'd better write a helper function in codebehind and call this
      function to perform transform in your databinding control.

      Here is a test function I've written which accept an input string and
      transform it to output html hyperlinks:

      =============== ============
      protected void Page_Load(objec t sender, EventArgs e)
      {
      string ret =parse_string(" Earth.New Zealand.Aucklan d.Henderson.New
      Account");

      Response.Write( "<br/>" + ret);
      }

      string parse_string(st ring input)
      {
      const string stmp = "<a
      href='http://www.mysite.com/showgroups/?GroupName={1}' >{0}</a>";


      string[] items1 = input.Split('.' );
      string[] items2 = new string[items1.Length];

      for (int i = 0; i < items1.Length; ++i)
      {
      items2[i] =string.Join(". ", items1, 0, i + 1);
      }


      StringBuilder sb = new StringBuilder() ;
      sb.AppendFormat (stmp, items1[0], items2[0]);

      for (int i = 1; i < items1.Length; ++i)
      {
      sb.Append("."); sb.AppendFormat (stmp, items1[i], items2[i]);
      }
      return sb.ToString();

      }
      =============== ==========

      You can call this funcction in your databinding control to format the
      certain data field (string value).

      Hope this helps.

      Sincerely,

      Steven Cheng

      Microsoft MSDN Online Support Lead


      Delighting our customers is our #1 priority. We welcome your comments and
      suggestions about how we can improve the support we provide to you. Please
      feel free to let my manager know what you think of the level of service
      provided. You can send feedback directly to my manager at:
      msdnmg@microsof t.com.

      =============== =============== =============== =====
      Get notification to my posts through email? Please refer to
      Gain technical skills through documentation and training, earn certifications and connect with the community

      ications.

      Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
      where an initial response from the community or a Microsoft Support
      Engineer within 1 business day is acceptable. Please note that each follow
      up response may take approximately 2 business days as the support
      professional working with you may need further investigation to reach the
      most efficient resolution. The offering is not appropriate for situations
      that require urgent, real-time or phone-based interactions or complex
      project analysis and dump analysis issues. Issues of this nature are best
      handled working with a dedicated Microsoft Support Engineer by contacting
      Microsoft Customer Support Services (CSS) at
      http://msdn.microsoft.com/subscripti...t/default.aspx.
      =============== =============== =============== =====
      This posting is provided "AS IS" with no warranties, and confers no rights.

      --------------------
      >From: "Mark B" <none@none.co m>
      >Subject: 2 Datagrid columns questions
      >Date: Thu, 29 May 2008 23:03:09 +1200
      >
      >I have a Datagrid working fine, outputting:
      >
      >Group
      >Most Popular Product Code
      >--------
      >-------------------------------
      >
      >Earth.New Zealand
      >32
      >Earth.New Zealand
      >32
      >Earth.New Zealand.Aucklan d
      >32
      >Earth.New Zealand.Aucklan d
      >32
      >Earth.New Zealand.Aucklan d.Auckland
      >7
      >Earth.New Zealand.Aucklan d.Auckland.Parn ell
      >7
      >Earth.New Zealand.Aucklan d.Henderson
      >10024
      >Earth.New Zealand.Aucklan d.Henderson.New Account
      >10024
      >Earth.United States
      >32
      >Earth.United States.Texas
      >32
      >
      >
      >Now I want to do these 2 things:
      >
      >1) Have clickable hyperlinks on each sub-group and not the periods e.g.
      for
      >the last entry above (Earth.United States.Texas):
      >
      ><a href="http://www.mysite.com/showgroups/?GroupName=Eart h">Earth</a>.<a
      >href="http://www.mysite.com/showgroups/?GroupName=Eart h.United
      >States">Unit ed States</a>.<a
      >href="http://www.mysite.com/showgroups/?GroupName=Eart h.United
      >States.Texas"> Texas</a>
      >
      >I still want people to be able to sort the column as displayed though.
      >
      >
      >2) Rather than display the Most Popular Product Code (SQL int), I want the
      >result of the function fConvertCodeToP roductTitle(lng ProductID as Long) as
      >String. I still want people to be able to sort by the long integer value
      >though -- even though I don't want it displayed for the column.
      >
      >How can I do this with the Datagrid control (Visual Web Developer 2008
      >Express)?
      >
      >TIA
      >
      >

      Comment

      Working...