Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
75
How to add a column containing a hyperlink?
posted

Hi,

This is more of a conceptual questions, rather than a coding question. I would like to double-check my approach to my current issue.

 

What I want to do:

  • I want to have a column in my grid that contains a button/image with a URL in the WebDataGrid
  • the URL contains a URL portion that is dependant on data in the current row
  • the button/image will also have a tooltip that contains row-specific data

My current approach

  • I believe that I need to use a Row Item Template for the column that contains the button
  • This template includes an <asp:HyperLink> control
  • The properties of this control (NavigationUrl, ImageUrl, etc.) will be set using template control binding

Complicating factor:

  • There are a list of things that are known only at runtime...not design-time
  • This list includes: 1) the number of these "button/link" columns 2) the button image

 

Because of this complicating factor, I believe that I need to be creating/adding the Row Item Template programmatically (rather than in markup). I am having some other issues with this (see http://community.infragistics.com/forums/p/60078/305112.aspx). However, my main questions in this post are these:

  • Is this approach (conceptually) the right way to go?
  • Is there a simpler way to do what I want to do?

 

Regards,

Joel

 

Parents
No Data
Reply
  • 19693
    Verified Answer
    posted

    Hello Joel,

    Thank you for your interest in WebDataGrid.

    This approach is the right way to implement this requirements.

    I have replied to the other post.

    You can use the WebImageButton to implement the button image column:

        private class CustomItemTemplate : ITemplate

        {

            #region ITemplate Members

     

            public void InstantiateIn(Control container)

            {

                CheckBox chkBox = new CheckBox();

                chkBox.ID = "TemplateCheckBox";

                // Get the cell value from the DataItem

                chkBox.Checked = (bool)((DataRowView)((TemplateContainer)container).DataItem)["BoolColumn"];

     

                HyperLink link = new HyperLink();

                link.ID = "TemplateHyperLink";

                string dataValue = (string)((DataRowView)((TemplateContainer)container).DataItem)["Data"];

                link.NavigateUrl = string.Format("http://www.google.bg/search?q={0}", dataValue);

                link.Text = (string)((DataRowView)((TemplateContainer)container).DataItem)["Data"];          

     

                WebImageButton imgBtn = new WebImageButton();

                imgBtn.ID = "TemplateWebImageButton";

                imgBtn.CommandArgument = (string)((DataRowView)((TemplateContainer)container).DataItem)["Item"];

                imgBtn.Appearance.Image.Url = "~/ig_res/Default/images/add_down.gif";

     

                container.Controls.Add(link);

                container.Controls.Add(chkBox);

                container.Controls.Add(imgBtn);

            }

            #endregion

        }

    Let me know if you need further assistance

Children