TheWebGuy38
asked on
Binding a Datatable to a datalist
I did this a long time ago for testing purposes but I can't remember what I did.
all I want to do is bind a datatable to a datalist.
If i recall, I had to fill the datatable or pass it into a dataset before putting it in the datalist.
this is my code which is not filling the datalist
any help appreciated
Dim Dt As DataTable = New DataTable("Table")
Dim Title As DataColumn = New DataColumn("Title", GetType(String))
Dim Picture As DataColumn = New DataColumn("Picture", GetType(String))
'-- Add Data Column to DataTable --//
Dt.Columns.Add(Title)
Dt.Columns.Add(Picture)
'-- Add Data Rows to DataTable --//
Dim Dr1 As DataRow = Dt.NewRow
Dr1("Picture") = "Images/C.jpg"
Dr1("Title") = "Pic 1"
Dim Dr2 As DataRow = Dt.NewRow
Dr2("Picture") = "Images/d.jpg"
Dr2("Title") = "Pic 2"
Dim Dr3 As DataRow = Dt.NewRow
Dr3("Picture") = "Images/4potsandacup.jpg"
Dr3("Title") = "Pic 3"
Dt.Rows.Add(Dr1)
Dt.Rows.Add(Dr2)
Dt.Rows.Add(Dr3)
DataList1.DataSource = Dt
DataList1.DataBind()
all I want to do is bind a datatable to a datalist.
If i recall, I had to fill the datatable or pass it into a dataset before putting it in the datalist.
this is my code which is not filling the datalist
any help appreciated
Dim Dt As DataTable = New DataTable("Table")
Dim Title As DataColumn = New DataColumn("Title", GetType(String))
Dim Picture As DataColumn = New DataColumn("Picture", GetType(String))
'-- Add Data Column to DataTable --//
Dt.Columns.Add(Title)
Dt.Columns.Add(Picture)
'-- Add Data Rows to DataTable --//
Dim Dr1 As DataRow = Dt.NewRow
Dr1("Picture") = "Images/C.jpg"
Dr1("Title") = "Pic 1"
Dim Dr2 As DataRow = Dt.NewRow
Dr2("Picture") = "Images/d.jpg"
Dr2("Title") = "Pic 2"
Dim Dr3 As DataRow = Dt.NewRow
Dr3("Picture") = "Images/4potsandacup.jpg"
Dr3("Title") = "Pic 3"
Dt.Rows.Add(Dr1)
Dt.Rows.Add(Dr2)
Dt.Rows.Add(Dr3)
DataList1.DataSource = Dt
DataList1.DataBind()
post ur Datalist's markup
ASKER
<asp:DataList ID="DataList1" runat="server" width="100%">
<ItemTemplate>
<div style="padding: 5px">
<img id="imgRender" runat="server" src='<%# DataBinder.Eval(Container. DataItem, "Picture") %>'
border="1" width="350"/>
</div>
</ItemTemplate>
</asp:DataList>
<ItemTemplate>
<div style="padding: 5px">
<img id="imgRender" runat="server" src='<%# DataBinder.Eval(Container.
border="1" width="350"/>
</div>
</ItemTemplate>
</asp:DataList>
HI
bind a DataTable in a DataList control. Just for the simplicity of this demo
Bellow url give some infoirmation
http://geekswithblogs.net/dotNETvinz/archive/2009/08/13/bind-datatable-to-datalist-control.aspx
bind a DataTable in a DataList control. Just for the simplicity of this demo
Bellow url give some infoirmation
http://geekswithblogs.net/dotNETvinz/archive/2009/08/13/bind-datatable-to-datalist-control.aspx
ASKER
The datalist is bound to the table
DataList1.DataSource = Dt
DataList1.DataBind()
I had this problem before. I think I had to fill the datalist or something
DataList1.DataSource = Dt
DataList1.DataBind()
I had this problem before. I think I had to fill the datalist or something
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.