2 Datagrid columns questions

M

Mark B

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
 
S

Steven Cheng [MSFT]

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 =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, items2);
}
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:
(e-mail address removed).

==================================================
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" <[email protected]>
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
--------
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top