473,396 Members | 2,109 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

DataNavigateUrlFormatString

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
Nov 17 '05 #1
1 7557
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[i] = curRow[m_DataNavigateUrlFields[i]].ToString();
link.NavigateUrl =
String.Format(System.Globalization.CultureInfo.Inv ariantCulture,
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
Nov 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Mike P | last post by:
Does anyone know if you can pass multiple column parameters in the DataNavigateUrlFormatString for grids? My current code is like this and works for a single parameter: <asp:HyperLinkColumn...
2
by: TJS | last post by:
how can I dynamically set the value of DataNavigateUrlFormatString in a hyperlink column I have the value to use, I need the correct syntax . "<%= %>" isn't working <asp:HyperLinkColumn...
0
by: RobT | last post by:
Hi, I've been using the DataGrid control in my ASP.NET web page. The page is used to search for records in the database. The control is bound to a DataSource and gets populated ok. I am also...
1
by: Fredrik Rodin | last post by:
Hi! I'm about to create a datagrid and columns at runtime. The problem I have is to add additional arguments to the querystring. The code: Dim hc1 As New HyperLinkColumn hc1.DataTextField...
0
by: josepm | last post by:
Hello. I am programming a bounded DataGrid in C# (VS 2003) for ASP.Net 1.1 environment. My trouble is an HyperLinkColumn inside this DataGrid becaus I do not know how to change the...
7
by: genc_ymeri | last post by:
Hi, I would like to bind the hyperlink column but I don't see how to. I tried somethink like this but instead of showing ID nummbers it shows "ID=ID" Any tip is very much appreciated. Genc
3
by: msuk | last post by:
All, I am using a datagrid on a 1.1 .aspx page that has a hyperlink column. I am using 'DataNavigateUrlFormatString' to set the URL to browse to once the user clicks on the link i.e. ...
2
by: Ixnay | last post by:
Thanks in advance for any help you can give me on this. I am trying to include the value from a request.querystring in the DataNavigateUrlFormatString I am able to include one of the values...
2
by: Vincent | last post by:
Hi, I have a problem when I put the 3rd field into a hyperlink field it does not show up. Here's my example: This works and the url is: http://gl.aspx?whs=1&dept=02 <asp:HyperLinkField...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.