473,406 Members | 2,713 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,406 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 7558
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.