Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > DataNavigateUrlFormatString

Reply
Thread Tools

DataNavigateUrlFormatString

 
 
Coder Coder
Guest
Posts: n/a
 
      07-09-2003
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
 
Reply With Quote
 
 
 
 
Joshua Flanagan
Guest
Posts: n/a
 
      08-06-2003
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


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
DataNavigateUrlFormatString Mike P ASP .Net 2 10-10-2008 07:16 AM
Please help with DataNavigateUrlFormatString property issue with the DataGrid RobT ASP .Net 0 04-15-2004 03:49 PM
set value for DataNavigateUrlFormatString dynamically TJS ASP .Net 2 02-26-2004 11:22 PM
Re: DataNavigateUrlFormatString Mike P ASP .Net 0 08-11-2003 02:55 PM
DataNavigateUrlFormatString Raymond ASP .Net 0 07-11-2003 04:27 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57