




















Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!





















Understanding the ASP.NET data binding model
In the ASPX page (not the C# file), we embed expressions in some “special” expressions
Data binding has a place in the page lifecycle It occurs automatically in some cases depending on the setting of control properties In some cases you must force the binding to execute Call DataBind() on the page or control this.DataBind()
Use data binding to call a function on the current page (The function is named SampleFunction)
See DataBindingExpressions1.aspx
<asp:Label ID="Label2" runat="server" Text="<%# SampleFunction() %>"> </asp:Label>
Anything that can be enumerated (foreach loop) can serve as a data source Collections for example Dictionary and so on ADO.NET DataSet and DataTable We bind controls to data sources
Repeated (list) We bind to a list (hence repeating data) Repeated data bind is used with “list” controls
Controls can be bound to a data source Basically, repeating controls are of three types List controls use a template for each item found in the data source Iterative controls allow you to create a custom template for each row that is bound View controls are the richest ( DetailsView , FormView , GridView ) More later
DataSourceID: Set to an Access, SQL or other DataSource control It’s a quoted string DataSource : Set to a bindable source DataValueField : Set to the data source field that you want the to behave as a key DataTextField : Set to the data source field that you want the user to see The DataKeyField contains the primary key docsity.com
They add a layer of abstraction to simplify your life They create the OleDbDataAdapter, DataSet and DataTable for you They take care of the binding details too
SqlDataSource AccessDataSource ObjectDataSource XmlDataSource
And more
The DataSourceID property of a grid or other control contains the name of a data source control Such as AccessDataSource , ObjectDataSource , SqlDataSource
Programmatically bind a ListBox
lstDemo.DataSourceID = AccessDataSource1"; lstDemo.DataTextField = "fldInvoiceNumber"; lstDemo.DataBind();