Tuesday, April 16, 2013

GridView TemplateField in asp.net || how to bind the Data in Gridview TemplateField in asp.net


Inprevious posts i have given examples on how to export data from gridview to excel,Bind dropdown in gridview .Here i will explain the gridview template fields. Template field is used for complex content and it is unlimited and also can be used for any type of presentation.It is both attribute based and content based for producing output.It's content is defined using templates.A template is an area where we can present any type of data .Template fields has no attribute for retrieving data from data objects and it uses asp.net data binding expressions to retrieve data and support data binding.The following syntax and statement are used for writing data bind expressions
<%# data bind expression #>
<%# Eval("filedname") #> (2.0)
<%# Bind("filedname") #>
<%# DataBinder.Eval(container.DataItem,"filedname")%>
The last method is the older asp.net method

Eval gets data from data object and bind gets data from data object like eval but also sends data back to data object for changes,It is conditional
Note:db expression can be written separately inside templates and also along with properties of controls when used.Along with properties.we must enclose them in single quotes
<asp TextBox Text='<%#Eval("job_id")%>'> </asp:Texbox>

No comments:

Bel