DataNavigateUrlFormatString

Discussion in 'ASP .Net' started by Coder Coder, Jul 9, 2003.

  1. Coder Coder

    Coder Coder Guest

    Hi I want the DataNavigateUrlFormatString value to be of a couple of
    different variables

    such as:
    DataNavigateUrlFormatString="mypage?val={0}&val2={1}



    where now I have the following working
    DataNavigateUrlFormatString="mypage?val="{0}

    - thanks
     
    Coder Coder, Jul 9, 2003
    #1
    1. Advertising

  2. Use multiple fields for DataNavigateUrlFormatString SOLUTION!

    I've come up with a pretty good solution to the problem of needing to build
    the NavigateUrl using multiple data values. My solution is partially based
    on code from this article: http://tripleasp.net/tutorial.aspx?NavID=27

    You need to use a TemplateColumn instead of a HyperLinkColumn. But in order
    to build a TemplateColumn dynamically, you need a class that implements
    ITemplate. I've created such a class which I feel solves this problem quite
    nicely.

    Using the class is as simple as:

    TemplateColumn linkCol = new TemplateColumn();
    linkCol.ItemTemplate = new MultiSourceHyperLinkTemplate("orderItemName",
    "ShowItem.aspx?order={0}&item={1}",
    new string[]{"orderNumber", "orderItemNumber"});
    DataGrid1.Columns.Add(linkCol);

    The above example assumes that orderItemName, orderNumber, and
    orderItemNumber are all column names in the datasource for the datagrid.
    The majority of the work is done by the MultiSourceHyperLinkTemplate class,
    defined below:

    public class MultiSourceHyperLinkTemplate : System.Web.UI.ITemplate
    {
    string m_DataTextField;
    string m_DataNavigateUrlFormatString;
    string[] m_DataNavigateUrlFields;

    public MultiSourceHyperLinkTemplate(string dataTextField, string
    navigateUrlFormatString, string[] navigateUrlFields)
    {
    m_DataTextField = dataTextField;
    m_DataNavigateUrlFormatString = navigateUrlFormatString;
    m_DataNavigateUrlFields = navigateUrlFields;
    }

    private void BindData(object sender, EventArgs e)
    {
    HyperLink link = (HyperLink) sender;
    DataGridItem container = (DataGridItem) link.NamingContainer;
    DataRowView curRow = (DataRowView) container.DataItem;
    link.Text = curRow[m_DataTextField].ToString();
    // evaluate each of the data fields
    string[] navigateUrlValues = new string[m_DataNavigateUrlFields.Length];
    for (int i = 0; i < m_DataNavigateUrlFields.Length; ++i)
    navigateUrlValues = curRow[m_DataNavigateUrlFields].ToString();
    link.NavigateUrl =
    String.Format(System.Globalization.CultureInfo.InvariantCulture,
    m_DataNavigateUrlFormatString, navigateUrlValues);

    }

    #region ITemplate Members

    public void InstantiateIn(System.Web.UI.Control container)
    {
    HyperLink link = new HyperLink();
    link.DataBinding += new EventHandler(BindData);
    container.Controls.Add(link);
    }

    #endregion

    #region Property accessors
    string DataTextField { get { return m_DataTextField; } set {
    m_DataTextField = value; } }
    string DataNavigateUrlFormatString { get { return
    m_DataNavigateUrlFormatString; } set { m_DataNavigateUrlFormatString =
    value; } }
    string[] DataNavigateUrlFields { get { return m_DataNavigateUrlFields; }
    set { m_DataNavigateUrlFields = value; } }
    #endregion
    }


    Enjoy!
    -Joshua Flanagan
     
    Joshua Flanagan, Aug 6, 2003
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Raymond

    DataNavigateUrlFormatString

    Raymond, Jul 11, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    551
    Raymond
    Jul 11, 2003
  2. Mike P

    DataNavigateUrlFormatString

    Mike P, Aug 11, 2003, in forum: ASP .Net
    Replies:
    2
    Views:
    3,742
    satheshram
    Oct 10, 2008
  3. Mike P

    Re: DataNavigateUrlFormatString

    Mike P, Aug 11, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    502
    Mike P
    Aug 11, 2003
  4. TJS
    Replies:
    2
    Views:
    3,063
  5. RobT
    Replies:
    0
    Views:
    883
Loading...

Share This Page