Thanks for reading! To save you a lot of choppy copying and pasting, here's all the code in one big chunk:
<%@ Page Language="VB" Debug="true" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.OleDb" %>
<script runat="server">
sub page_load( source as Object, e as EventArgs )
if not isPostBack then
doBinding()
end if
end sub
Sub doBinding()
Dim strConn As String = "Provider=Microsoft.Jet.OLEDB.4.0; " & _
"Ole DB Services=-4; " & _
"Data Source=C:\Inetpub\wwwroot\test.mdb"
Dim dbConnection As OleDbConnection = New OleDbConnection(strConn)
Dim strSQL As String = "SELECT * FROM products"
Dim dataAdapter As OleDbDataAdapter = New OleDbDataAdapter( strSQL, strConn)
Dim dataSet As DataSet = new DataSet
dataAdapter.Fill(dataSet)
dList.DataSource = dataSet
dList.DataBind()
End Sub
Sub getItem( s as object, e as DataListCommandEventArgs )
dList.SelectedIndex = e.Item.ItemIndex
doBinding()
End Sub
Sub editItem( s as object, e as DataListCommandEventArgs )
dList.EditItemIndex = e.Item.ItemIndex
doBinding()
End Sub
Sub UpdateItem( s as object, e as DataListCommandEventArgs )
End Sub
Sub DeleteItem( s as object, e as DataListCommandEventArgs )
End Sub
Sub doCancel( s as object, e as DataListCommandEventArgs )
dList.SelectedIndex = -1
dList.EditItemIndex = -1
doBinding()
End Sub
</script>
<html>
<head>
</head>
<body>
<form runat="server">
<asp:DataList id="dList" runat="server"
onItemCommand="getItem"
OnEditCommand="editItem"
OnUpdateCommand="UpdateItem"
OnDeleteCommand="DeleteItem"
OnCancelCommand="doCancel"
RepeatDirection="Horizontal" RepeatColumns="3">
<ItemTemplate>
<asp:LinkButton runat="server" commandName="select"><%# Container.DataItem("description") %></asp:LinkButton>
<br />
<img src='<%# Container.DataItem("imgPath") %>' />
</ItemTemplate>
<SelectedItemStyle BackColor="#CCCCCC">
</SelectedItemStyle>
<SelectedItemTemplate>
Desc: <%# Container.DataItem("description") %>
<br />
Mfg: <%# Container.DataItem("manufacturer") %>
<br />
Color: <%# Container.DataItem("color") %>
<br />
Cost: <%# FormatCurrency( Container.DataItem("price")) %>
<br />
<img src='<%# Container.DataItem("imgPath") %>' /><br />
<asp:LinkButton runat="server" commandName="edit" text="edit" />
</SelectedItemTemplate>
<EditItemTemplate>
Desc:
<asp:TextBox runat="server" id="desc" text='<%# Container.DataItem("description") %>' />
<br />
Mfg: <asp:TextBox runat="server" id="mfg" text='<%# Container.DataItem("manufacturer") %>' />
<br />
Color: <asp:TextBox runat="server" id="clr" text='<%# Container.DataItem("color") %>' />
<br />
Cost: <asp:TextBox runat="server" id="cst" text='<%# Container.DataItem("price") %>' />
<br />
Img: <asp:TextBox runat="server" id="img" text='<%# Container.DataItem("imgPath") %>' /><br />
<asp:LinkButton runat="server" commandName="Update" text="upd" /> |
<asp:LinkButton runat="server" commandName="Delete" text="del" /> |
<asp:LinkButton runat="server" commandName="Cancel" text="cancel" />
</EditItemTemplate>
</asp:DataList>
</form>
</body>
</html>
| DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware. |