15 October 2007

Passing two arguments in DataNavigateUrlFormatString in hyperlink field of .NET 2.0 Grid-View

In a hyperlink column of gridview, suppose the value of the property DataNavigateUrlFormatString is “ProductsForSupplierDetails.aspx?SupplierID={0}”. Many people think that the argument {0} is replaced by the value of the property DataKeyNames of the Gridview. But in actual case this is replaced by the value of the property DataNavigateUrlFields of the hyperlink column.

Now suppose you want to pass two arguments instead of one, something like this “ProductsForSupplierDetails.aspx?SupplierID={0}&CompanyName={1}”.

Now as these two arguments come from property DataNavigateUrlFields of the hyperlink column. So value of this property has to be “DataNavigateUrlFields="SupplierID,CompanyName”.

At run time the .NET replaces {0} with “SupplierID” and {1} with “CompanyName” of that row.

Pretty simple and straightforward it seems but I have seen many people struggling with this simple concept. Also I found wrong answers for this problem in some .NET forums. Hence thought to post it here for benefit of masses.

5 comments:

Anonymous said...

nice article! Thanks

Anonymous said...
This comment has been removed by a blog administrator.
Anonymous said...

It is remarkable, rather valuable idea

Anonymous said...

Remarkable phrase and it is duly

Anonymous said...

Bravo, what necessary words..., an excellent idea