Thursday, February 5, 2009

Acessing Data Using Data Repeater

Accessing Data Using Data Repeater:

Data Repeater repeats the specified data-bound templates without applying any sort of additional formatting. For example, the Repeater doesn't create a table or a vertical or horizontal list of data by default. You determine the final layout of the generated markup by creating ASP.NET templates and explicitly adding markup that separates one row from the next.

HTML File


<asp:repeater id="Repeater1" runat="server">
<ItemTemplate>
<%# DataBinder.Eval(Container.DataItem,"AssetType")%>
</ItemTemplate>
<SeparatorTemplate>
</br>
</SeparatorTemplate>
</asp:repeater>

DataBinder.Eval method is used to declare which members of the DataItem to use in the output. The Eval method uses reflection to get the second parameter from the first. This approach typically has Container.DataItem as the first parameter, which yields a DataRowView. The second parameter is the name of the data field within the DataRowView



Code behind (Using Data Reader)

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load


Dim Objconn As New OleDbConnection
Dim objreader As OleDbDataReader
Dim strsql As String
Dim strconnection As String


''Connection String from web.config file

strconnection = ConfigurationSettings.AppSettings("Dbconn")
Objconn = New OleDb.OleDbConnection(strconnection)
Objconn.Open()
Dim ds As DataSet = New DataSet

strsql = " Select distinct AssetType as AssetType from AM_AssetType order by assettype"

Dim objcommand As New OleDbCommand(strsql, Objconn)

objreader = objcommand.ExecuteReader

Repeater1.DataSource = objreader
Repeater1.DataBind()



End Sub

Code behind (Using Data Adapter)

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load


Dim Objconn As New OleDbConnection
Dim Objadapter As New OleDbDataAdapter
Dim Objds As New DataSet
Dim strsql As String


''Connection String from web.config file

strconnection = ConfigurationSettings.AppSettings("Dbconn")
Objconn = New OleDb.OleDbConnection(strconnection)
Objconn.Open()
Dim ds As DataSet = New DataSet

strsql = " Select distinct AssetType as AssetType from AM_AssetType order by assettype"

Objadapter = New OleDbDataAdapter(strsql, Objconn)
Objadapter.SelectCommand.CommandTimeout = 50000
Objadapter.Fill(ds)

Repeater1.DataSource = objreader
Repeater1.DataBind()
End Sub

Is Data Reader Disconnected ?

DataReader is connected. However, DataTable and DataSet are disconnected (in-memory).you can't have a new DataReader for a connection if there is another one already active.




No comments:

Post a Comment