web 2.0

ASP.NET(vb.net) & DataList - Repeat Multiple Columns

ASP.NET(vb.net) & DataList - Repeat Multiple Columns Example scripts how to use DataList control in asp.net , Gets or sets the number of columns to display in the DataList control.

ShotDev Focus:
- ASP.NET(vb.net) & DataList - Repeat Multiple Columns

Example

DataListRepeatColumns.aspx

  1. <%@ Import Namespace="System.Data"%>  
  2. <%@ Import Namespace="System.Data.OleDb"%>  
  3. <%@ Page Language="VB" %>  
  4. <script runat="server">  
  5. Dim objConn As OleDbConnection  
  6. Dim objCmd As OleDbCommand  
  7.   
  8. Sub Page_Load(sender As Object, e As EventArgs)  
  9. Dim strConnString As String  
  10. strConnString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="& _  
  11. Server.MapPath("database/mydatabase.mdb")&";"  
  12. objConn = New OleDbConnection(strConnString)  
  13. objConn.Open()  
  14.   
  15. BindData()  
  16. End Sub  
  17.   
  18. Sub BindData()  
  19. Dim strSQL As String  
  20. strSQL = "SELECT * FROM category"  
  21.   
  22. Dim dtReader As OleDbDataReader  
  23. objCmd = New OleDbCommand(strSQL, objConn)  
  24. dtReader = objCmd.ExecuteReader()  
  25.   
  26. '*** BindData to DataList ***'  
  27. myDataList.DataSource = dtReader  
  28. myDataList.DataBind()  
  29.   
  30. dtReader.Close()  
  31. dtReader = Nothing  
  32.   
  33. End Sub  
  34.   
  35. Sub Page_UnLoad()  
  36. objConn.Close()  
  37. objConn = Nothing  
  38. End Sub  
  39.   
  40. </script>  
  41. <html>  
  42. <head>  
  43. <title>ShotDev.Com Tutorial</title>  
  44. </head>  
  45. <body>  
  46. <form id="form1" runat="server">  
  47. <asp:DataList id="myDataList" runat="server">  
  48. <HeaderTemplate>  
  49. <b>My Category</b>  
  50. </HeaderTemplate>  
  51. <ItemTemplate>  
  52. <div align="center">  
  53. <img src="images/<%#Container.DataItem("Picture")%>">  
  54. <br />  
  55. <%#Container.DataItem("CategoryName")%>  
  56. </div>  
  57. </ItemTemplate>  
  58. <SeparatorTemplate>  
  59. <hr />  
  60. </SeparatorTemplate>  
  61. </asp:DataList>  
  62. </form>  
  63. </body>  
  64. </html>  

Create a asp.net file and save to path root-path/dotnet/

Run
http://localhost/dotnet/DataListRepeatColumns.aspx

Screenshot

ASP.NET(vb.net) & DataList - Repeat Multiple Columns
.
.
.

Download this script.
Download

1 Star2 Stars3 Stars4 Stars5 Stars6 Stars7 Stars8 Stars9 Stars10 Stars (No Ratings Yet)
Loading ... Loading ...

Leave a Reply

You must be logged in to post a comment.