Posted by Abhijit Jana in .NET 4.0, ASP.NET, C#.
Tags: ASP.Net, Beginners, Binding, BindingExpression, GridView, ItemTemplates
GridView TemplateField allow us to specify custom controls, multiple fields and Html using a custom template. TemplateField allows us to define a completely customized template for GridView Column. We can bind the data with in template control using binding expression. ASP.NET provides number of ways to take control over the template control. In this post I am going to discuss how we can set template control visibility based on certain condition which depends on the data source data. For example, imagine you have a link button within template field. You want to set visibility if that control based on the some value of your data source.
Posted by Abhijit Jana in ASP.NET, Tips and Tricks, Visual Studio.
Tags: ASP.Net, Beginners, codeproject, GridView, How To, HyperLinkField, Multiple Parameter, NavigateURL
Few days back I have published an article “How to pass multiple values using GridView HyperLinkField ?”, where I have explained how you can pass multiple parameter with Gridview HyperLinkField using DataNavigationUrlField and DataNavigateUrlFormatString properties. In this post, I am going to explain how you can pass some external values as parameters with the same hyperlink field.
DataNavigationUrlField use only those fields as parameter which are the part of GridView DataSource. Now the problem comes when you want to pass some other variables as parameter which are not part of the DataSource. As shown in below image we are passing EmpID and ParentId as argument and this two field are the data member of GridView DataSource.
Now Say, You want pass ChildID for that particular record along with ParentID and EmpID and you want hyperlink url should be like “Default.aspx?EmpID=1&ParentID=P1&ChildID=C1”where ChildID is not part of datasource.
You can achieve this by writing code in code behind for the particular GridView. There is two events where you can overwrite the navigation url of that hyperlink field. You can use Gridview_RowDataBound or Gridview_PreRender for the same.