Hi guys,
Just using these small snippet below using Datalist with sorting!
But it appears i can see no Data on the screen when compiled with Visual
Studio .Net!
With WebMatrix its running fine!:)
Whats missing in VStudio .Net?
Imports System.Data.SqlClient
Imports System.Data
Imports System.Web.UI.WebControls
Imports System.Web.UI.HtmlControls
Public Class sort_datalist
Inherits System.Web.UI.Page
Protected WithEvents MyDataList As System.Web.UI.WebControls.DataList
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
End Sub
'NOTE: The following placeholder declaration is required by the Web Form
Designer.
'Do not delete or move it.
Private designerPlaceholderDeclaration As System.Object
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub
#End Region
Dim myView As DataView
Private Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
If Not IsPostBack Then
PullCategories()
myView.Sort = "CategoryName"
PopulateCategories()
End If
End Sub
Sub SortByName_Click(ByVal sender As Object, ByVal e As EventArgs)
PullCategories()
myView.Sort = "CategoryName"
PopulateCategories()
End Sub
Sub SortByDescription_Click(ByVal sender As Object, ByVal e As EventArgs)
PullCategories()
myView.Sort = "Description"
PopulateCategories()
End Sub
Sub PullCategories()
Dim myTable As New DataTable
Dim myConn As New
SqlConnection("Server=localhost;Database=Northwind ;integrated security=true;")
Dim myAdapter As New SqlDataAdapter("Select CategoryName,
Description FROM Categories", myConn)
myAdapter.Fill(myTable)
myView = New DataView(myTable)
End Sub
Sub PopulateCategories()
MyDataList.DataSource = myView
MyDataList.DataBind()
End Sub
End Class
--------------------------------
<asp:DataList id="MyDataList" Runat="server" ItemStyle-BorderWidth="1">
<HeaderTemplate>
Sort By<asp:LinkButton ID="SortByName" Runat="server"
OnClick="SortByName_Click">Name</asp:LinkButton> /
<asp:LinkButton ID="SortByDescription" Runat="server"
OnClick="SortByDescription_Click">Description</asp:LinkButton>
</HeaderTemplate>
<ItemTemplate>
<%# Container.DataItem("CategoryName") %>
<br>
<%# Container.DataItem("Description") %>
</ItemTemplate>
</asp:DataList>