Products

Solutions

Resources

Partners

Community

Blog

About

QA

Ideas Test

New Community Website

Ordinarily, you'd be at the right spot, but we've recently launched a brand new community website... For the community, by the community.

Yay... Take Me to the Community!

Welcome to the DNN Community Forums, your preferred source of online community support for all things related to DNN.
In order to participate you must be a registered DNNizen

HomeHomeArchived Discus...Archived Discus...Developing Under Previous Versions of .NETDeveloping Under Previous Versions of .NETASP.Net 2.0ASP.Net 2.0Help with Dynamicly Created DatagridHelp with Dynamicly Created Datagrid
Previous
 
Next
New Post
8/31/2008 4:02 AM
 

I've got a datagrid that is created on-the-fly, but I don't know how I can get the 5th column to accept hyperlinks.  When I run the website, instead on the hyperlink object that I created in code, the grid only displays System.Web.UI.WebControls.HyperLink in the final column.  All of the other columns work as they should.

How can I get the hyperlink to show.

Any help is appreciated.

-Greg

Below is the relevant code:

 

ds;

ds =

ds.Tables.Add();

 

ds.Tables[0].Columns.Add(

ds.Tables[0].Columns.Add(

ds.Tables[0].Columns.Add(

ds.Tables[0].Columns.Add(

ds.Tables[0].Columns.Add(

 

 

<snip>

HyperLink

AmazonBuyLink.Text =

AmazonBuyLink.Target =

AmazonBuyLink.NavigateUrl = item.DetailPageURL;

dr[

ds.Tables[0].Rows.Add(dr);

AmazonBuyLink = new HyperLink();
"Buy Now";"_blank";"Purchase Links"] = AmazonBuyLink;
new DataSet();"Vendor");"Condition");"Sales Price");"Your Savings");"Purchase Links");DataRow dr;

 

 

DataSet

 
New Post
8/31/2008 9:57 PM
 

Unfortunately the post of your code got so scrambled that I couldn't tell what you were doing with respect to setting up the databinding attributes for that column of the datagrid. Generally the result that you are seeing (System.Web.UI.WebControls.Hyperlink) is due to not properly specifying the DataField property of a Bound Column or the DataNavigateURLField of a Hyperlink Column so that it maps to the correct DataColumn name of your DataTable.

If that suggestion doesn't help you find the problem, please try posting your code again. I've had the best results when posting code to switch into the "Source" view of the forum post editor and paste the code between < pre> and < /pre> tags. (Note: Remove the extra space following opening left angle symbol which I added to allow posting here).


Bill, WESNet Designs
Team Lead - DotNetNuke Gallery Module Project (Not Actively Being Developed)
Extensions Forge Projects . . .
Current: UserExport, ContentDeJour, ePrayer, DNN NewsTicker, By Invitation
Coming Soon: FRBO-For Rent By Owner
 
New Post
8/31/2008 11:42 PM
 

William,

Thanks for the response. I assumed that the problem was because the column was not set to accept hyperlinks, but for the life of me, I couldn't find an example of how to do it dynamicaly. (Plus, it was 4 AM adn I'd been working on this project for 6+ hours.)

I've since figured out how to make the column into a type of HyperLinkColumn (I was missing the typeof() in my earier attempts), but now I get en error when I try to assign a variable of type HyperLink to the HyperLinkColumn in the datarow. I've starred the line that's throwing the error in the code below. The error is: "Type of value has a mismatch with column typeCouldn't store < System.Web.UI.WebControls.HyperLink> in Purchase Links Column. Expected type is HyperLinkColumn."

I'm really at a loss now.

Thanks for any help that you may have to offer.

-Greg

 
		    DataSet ds;

                    ds = new DataSet();
                    ds.Tables.Add();

                    
                    ds.Tables[0].Columns.Add("Vendor");
                    ds.Tables[0].Columns.Add("Condition");
                    ds.Tables[0].Columns.Add("Sales Price");
                    ds.Tables[0].Columns.Add("Your Savings");
		    ds.Tables[0].Columns.Add("Purchase Links", typeof (HyperLinkColumn));

                    DataRow dr;
                    
< removed code regarding filling the first four columns which work as expected >
                    
                    HyperLink AmazonBuyLink = new HyperLink();

                    AmazonBuyLink.Text = "Buy Now";
                    AmazonBuyLink.Target = "_blank";
                    AmazonBuyLink.NavigateUrl = item.DetailPageURL;

                *** dr["Purchase Links"] = AmazonBuyLink; ***
		    ds.Tables[0].Rows.Add(dr);

		    DataGrid dg = new DataGrid();
                    dg.DataSource = ds;
                    dg.DataBind();
                    return dg;
 
New Post
9/10/2008 8:22 AM
 

I've updated the attached code and included the output.  I've tried sending a HyperLink object to the column as well as a HyperLinkField object.  The only difference is that instead of the "System.Web.UI.WebControls.HyperLink" output from the HyperLink object, the output reads "HyperLinkField". 

I'm really at a loss, and I truly believe that this should be a simple thing. 
 
All help is greatly appreciated.
 
-Greg
 
Here's code pertaining to the datagrid (I snipped out several sections that only added more rows, but all rows are created using the same method as show below), and the output is below that:

1                        DataSet ds;
2   
3                        ds = new DataSet();
4                        ds.Tables.Add();
5   
6                        ds.Tables[0].Columns.Add("Vendor");
7                        ds.Tables[0].Columns.Add("Condition");
8                        ds.Tables[0].Columns.Add("Sales Price");
9                        ds.Tables[0].Columns.Add("Your Savings");
10                       ds.Tables[0].Columns.Add("Purchase Links");
11                       
12                       DataRow dr;
13                       
14                       //Add eBay Store Data
15                       FindItemsAdvancedResponseType ebayResponse = grabEbayData(ShoppingType.Store);
16                                          
17                       if (ebayResponse.SearchResult != null)
18                       {
19                           //fill in a datarow with the ebay info
20                           dr = ds.Tables[0].NewRow();
21  
22                           dr["Vendor"] = "eBay (Store Items Only) as of: " + ebayResponse.Timestamp.ToString("g");
23                           dr["Condition"] = "New";
24  
25                           if (ebayResponse.SearchResult[0].ItemArray[0].ConvertedCurrentPrice.Value > 0)
26                           {
27                               salesPrice = ebayResponse.SearchResult[0].ItemArray[0].ConvertedCurrentPrice.Value.ToString();
28                           }
29                           else if (ebayResponse.SearchResult[0].ItemArray[0].BuyItNowPrice != null)
30                           {
31                               salesPrice = ebayResponse.SearchResult[0].ItemArray[0].BuyItNowPrice.ToString();
32                           }
33                           else
34                           {
35                               salesPrice = "Unavailable";
36                           }
37                           dr["Sales Price"] = salesPrice;
38  
39                           if (productInfo.CoverPrice >= 0)
40                           {
41                               savingsString = "Unknown - No Sales Price Given";
42  
43                               if (salesPrice != "Unavailable")
44                               {
45                                   savingsDollars = decimal.Parse(productInfo.CoverPrice.ToString()) - decimal.Parse(salesPrice);
46                                   savingsDollars = Math.Round(savingsDollars, 2);
47                                   savingsPercent = (savingsDollars / productInfo.CoverPrice) * 100;
48                                   savingsPercent = Math.Round(savingsPercent, 0);
49                                   savingsString = "$" + savingsDollars + " (" + savingsPercent + "%)";
50                               }
51  
52                           }
53                           else
54                           {
55                               savingsString = "Unknown - No List Price Given";
56                           }
57                           
58                           dr["Your Savings"] = savingsString;
59  
60                           HyperLink EbayBuyLink = new HyperLink();
61  
62                           EbayBuyLink.Text = "Buy Now";
63                           EbayBuyLink.Target = "_blank";
64                           EbayBuyLink.NavigateUrl = ebayResponse.SearchResult[0].ItemArray[0].ViewItemURLForNaturalSearch;
65  
66                           dr["Purchase Links"] = EbayBuyLink;
67  
68                           ds.Tables[0].Rows.Add(dr);
69                       }
70  
71                       if (ds.Tables[0].Rows.Count == 0)
72                       {
73                           dr = ds.Tables[0].NewRow();
74                           dr["Vendor"] = "There are currently no vendors that offer price comparisons offering this item. Please use the Purchase links above to purchase this item.";
75                           ds.Tables[0].Rows.Add(dr);
76                       }
77  
78                       DataGrid dg = new DataGrid();
79                       dg.DataSource = ds;
80                       dg.DataBind();
81                       dg.BorderWidth = 1;
82                       dg.BorderColor = System.Drawing.Color.Black;
83                       dg.BorderStyle = BorderStyle.Solid;
84                       dg.Caption = "Compare Prices at Major E-tailers";
85                       dg.AlternatingItemStyle.BackColor = System.Drawing.Color.Bisque;
86                       dg.AlternatingItemStyle.ForeColor = System.Drawing.Color.Black;
87                       dg.ItemStyle.HorizontalAlign = HorizontalAlign.Center;
88                       dg.ItemStyle.VerticalAlign = VerticalAlign.Middle;
89  
90                       return dg;

 
Output: 

Compare Prices at Major E-tailers Vendor

 
Condition
Sales Price
Your Savings
Purchase Links
Amazon.com as of: 9/3/2008 3:04 PM
New
$34.99
$15.00 (30%)
System.Web.UI.WebControls.HyperLink
Amazon Store as of: 9/3/2008 3:04 PM
New
$26.34
$23.65 (47%)
System.Web.UI.WebControls.HyperLink
Amazon Store as of: 9/3/2008 3:04 PM
Used
$23.95
$26.04 (52%)
System.Web.UI.WebControls.HyperLink
eBay (Store Items Only) as of: 9/3/2008 7:06 PM
New
13.95
$36.04 (72%)
System.Web.UI.WebControls.HyperLink
eBay (Auction Items Only) as of: 9/3/2008 7:06 PM
New/Used
0.99
$49.00 (98%)
System.Web.UI.WebControls.HyperLink

 
New Post
9/10/2008 11:13 PM
Accepted Answer 

The purchase links column is displaying "System.Web.UI.WebControls.HyperLink" or "System.Web.UI.WebControls.HyperLinkField" because these are the text values returned by the HyperLink or HyperLinkField controls' ToString method which is being called when the datagrid attempts to render that column during databinding when it encounters either webcontrol that you have stored in the datarow's "Purchase Links" column. There are several ways to correctly code this:

1. Instead of relying on the AutoGenerateColumns default behavior of the datagrid, you could set the grid's AutoGenerateColumns property to false and then create and add the appropriate type of column to the grid's Columns collection using a HyperLinkColumn control for the Purchase Links column. For this column, you would have to set the Text property to "Buy Now" - that is assuming that the same text appears in all rows of the column; the Target property to "_blank"; and the DataNavigateURLField to "Purchase Links". Then, instead of using a HyperLink control and attempting to store it in your datarow, simply set

dr["Purchase Link"] = ebayResponse.SearchResult[0].ItemArray[0].ViewItemURLForNaturalSearch;

when setting up the values in the datatable.

2. Since this is the only column you are having trouble with - note that it is the only one for which you were trying to store a control (not text) in the datatable - here's an even simpler approach: Continue to let the datagrid auto generate its columns as you are doing now. Don't use the Hyperlink control to build the link just build the html anchor string in code:

dr["Purchase Link"] = "< a href='" + ebayResponse.SearchResult[0].ItemArray[0].ViewItemURLForNaturalSearch + "' target='_blank'>Buy Now< /a >"

Note that I have had to insert an extra space after the first < and before the last > to post this string in the forum.


Bill, WESNet Designs
Team Lead - DotNetNuke Gallery Module Project (Not Actively Being Developed)
Extensions Forge Projects . . .
Current: UserExport, ContentDeJour, ePrayer, DNN NewsTicker, By Invitation
Coming Soon: FRBO-For Rent By Owner
 
Previous
 
Next
HomeHomeArchived Discus...Archived Discus...Developing Under Previous Versions of .NETDeveloping Under Previous Versions of .NETASP.Net 2.0ASP.Net 2.0Help with Dynamicly Created DatagridHelp with Dynamicly Created Datagrid


These Forums are dedicated to discussion of DNN Platform and Evoq Solutions.

For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

  1. No Advertising. This includes promotion of commercial and non-commercial products or services which are not directly related to DNN.
  2. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
  3. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  4. No Flaming or Trolling.
  5. No Profanity, Racism, or Prejudice.
  6. Site Moderators have the final word on approving / removing a thread or post or comment.
  7. English language posting only, please.
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out