A
Arpan
The following code displays records from a SQL Server 7 database table
in a DataList (when the page loads for the first time, all the records
under the column named "FName" in the DB table are displayed as links
which, when clicked, displays the records existing in the other columns
corresponding to the link clicked):
<%@ Page Language=VB Explicit="true" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SQLClient" %>
<html>
<script runat="server">
Sub Page_Load(ByVal obj As Object, ByVal ea As EventArgs)
Dim dSet As DataSet
Dim sqlConn As SqlConnection
Dim sqlDapter As SqlDataAdapter
sqlConn = New
SqlConnection("Server=(local);Database=DB1;UID=ud;PWD=pd")
sqlDapter = New SqlDataAdapter("SELECT * FROM tblUsers",
sqlConn)
dSet = New DataSet()
sqlDapter.Fill(dSet, "Users")
dlUsers.DataSource = dSet.Tables("Users").DefaultView
dlUsers.DataBind()
End Sub
Sub ItemList(ByVal obj As Object, ByVal ea As
DataListCommandEventArgs)
dlUsers.SelectedIndex = ea.Item.ItemIndex
dlUsers.DataBind()
End Sub
</script>
<body>
<form runat="server">
<aspataList ID="dlUsers" OnItemCommand="ItemList" DataKeyField="ID"
runat="server">
<ItemTemplate>
<asp:LinkButton ID="lnkFName" runat="server"><%#
Container.DataItem("FName") %></asp:LinkButton>
</ItemTemplate>
<SelectedItemTemplate>
<%# Container.DataItem("FName") & " " & Container.DataItem("LName")
%><br>
Phone:<%# Container.DataItem("Phone") %><br>
Address:<%# Container.DataItem("Address") %><br>
</SelectedItemTemplate>
</aspataList>
</form>
</body>
</html>
As such the above code works fine but what I fail to understand is how
does the sub named "ListItem" know which records have to be retrieved
from the different columns when a link is clicked? Is it because the
DataSet with all the records have already been loaded in the memory?
In other words, the "ListItem" sub executes the following SQL query:
SELECT * FROM tblUsers WHERE FName='" & <whichever link has been
clicked> & "'"
But the "ListItem" sub doesn't have any SQL query like above; so how is
it filtering the records based on the "FName" column & then displaying
them in the DataList?
Thanks,
Arpan
in a DataList (when the page loads for the first time, all the records
under the column named "FName" in the DB table are displayed as links
which, when clicked, displays the records existing in the other columns
corresponding to the link clicked):
<%@ Page Language=VB Explicit="true" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SQLClient" %>
<html>
<script runat="server">
Sub Page_Load(ByVal obj As Object, ByVal ea As EventArgs)
Dim dSet As DataSet
Dim sqlConn As SqlConnection
Dim sqlDapter As SqlDataAdapter
sqlConn = New
SqlConnection("Server=(local);Database=DB1;UID=ud;PWD=pd")
sqlDapter = New SqlDataAdapter("SELECT * FROM tblUsers",
sqlConn)
dSet = New DataSet()
sqlDapter.Fill(dSet, "Users")
dlUsers.DataSource = dSet.Tables("Users").DefaultView
dlUsers.DataBind()
End Sub
Sub ItemList(ByVal obj As Object, ByVal ea As
DataListCommandEventArgs)
dlUsers.SelectedIndex = ea.Item.ItemIndex
dlUsers.DataBind()
End Sub
</script>
<body>
<form runat="server">
<aspataList ID="dlUsers" OnItemCommand="ItemList" DataKeyField="ID"
runat="server">
<ItemTemplate>
<asp:LinkButton ID="lnkFName" runat="server"><%#
Container.DataItem("FName") %></asp:LinkButton>
</ItemTemplate>
<SelectedItemTemplate>
<%# Container.DataItem("FName") & " " & Container.DataItem("LName")
%><br>
Phone:<%# Container.DataItem("Phone") %><br>
Address:<%# Container.DataItem("Address") %><br>
</SelectedItemTemplate>
</aspataList>
</form>
</body>
</html>
As such the above code works fine but what I fail to understand is how
does the sub named "ListItem" know which records have to be retrieved
from the different columns when a link is clicked? Is it because the
DataSet with all the records have already been loaded in the memory?
In other words, the "ListItem" sub executes the following SQL query:
SELECT * FROM tblUsers WHERE FName='" & <whichever link has been
clicked> & "'"
But the "ListItem" sub doesn't have any SQL query like above; so how is
it filtering the records based on the "FName" column & then displaying
them in the DataList?
Thanks,
Arpan