Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / May 2008

Tip: Looking for answers? Try searching our database.

2 Datagrid columns questions

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Mark B - 29 May 2008 12:03 GMT
I have a Datagrid working fine, outputting:

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

Earth.New Zealand
32
Earth.New Zealand
32
Earth.New Zealand.Auckland
32
Earth.New Zealand.Auckland
32
Earth.New Zealand.Auckland.Auckland
7
Earth.New Zealand.Auckland.Auckland.Parnell
7
Earth.New Zealand.Auckland.Henderson
10024
Earth.New Zealand.Auckland.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=Earth">Earth</a>.<a
href="http://www.mysite.com/showgroups/?GroupName=Earth.United
States">United States</a>.<a
href="http://www.mysite.com/showgroups/?GroupName=Earth.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 fConvertCodeToProductTitle(lngProductID 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 - 29 May 2008 15:15 GMT
Hi

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

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.datagrid.itemd
atabound(VS.80).aspx


Best of luck

Munna

www.munna.shatkotha.com
Steven Cheng [MSFT] - 30 May 2008 04:04 GMT
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(object sender, EventArgs e)
   {
       string ret =parse_string("Earth.New Zealand.Auckland.Henderson.New
Account");

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

   string parse_string(string 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@microsoft.com.

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
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/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------
>From: "Mark B" <none@none.com>
>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
>--------                                                                  
 
>-------------------------------
>
[quoted text clipped - 41 lines]
>
>TIA

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.