473,407 Members | 2,312 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

Don't know how to Update ..

I'm experimenting by following instructions at this address:

http://quickstarts.asp.net/QuickStar.../datalist.aspx

on how to use the DataList.

I was trying out the update part and following the coding example almost
line for line, except for changing some names of object to suit my own
naming conventions. When I got to the Sub MyDataList_Update routine,
they left out the update code. Below is the link to their code example.

http://quickstarts.asp.net/QuickStar...lang=VB+Source

And here's the code sample from that page:
================================================== ==

<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>

<html>

<script language="VB" runat="server">

Sub PopulateList()

Dim DS As DataSet
Dim MyConnection As SqlConnection
Dim MyCommand As SqlDataAdapter

MyConnection = New
SqlConnection(ConfigurationManager.ConnectionStrin gs("Pubs").ConnectionString)
MyCommand = New SqlDataAdapter("select * from Titles where type
= 'business'", MyConnection)

DS = New DataSet()
MyCommand.Fill(DS, "Titles")

MyDataList.DataSource = DS.Tables("Titles").DefaultView
MyDataList.DataBind()
End Sub

Sub Page_Load(Sender As Object, E As EventArgs)

If Not (Page.IsPostBack)
PopulateList()
End If
End Sub

Sub MyDataList_Edit(Sender As Object, E As DataListCommandEventArgs)

MyDataList.EditItemIndex = CInt(e.Item.ItemIndex)
PopulateList()
End Sub

Sub MyDataList_Update(Sender As Object, E As DataListCommandEventArgs)

' database update left out for simplicity's sake...

Dim EditText As HtmlInputText
EditText = E.Item.FindControl("edit_price")

Message.InnerHtml = "Price Updated: " & EditText.Value
MyDataList.EditItemIndex = -1
PopulateList()
End Sub

Sub MyDataList_Cancel(Sender As Object, E As DataListCommandEventArgs)

MyDataList.EditItemIndex = -1
PopulateList()
End Sub

</script>

<body topmargin="0" leftmargin="0" marginwidth="0" marginheight="0">

<form runat="server">

<!-- #include virtual="header.inc" -->

<ASP:DataList id="MyDataList" RepeatColumns="2"
OnEditCommand="MyDataList_Edit" OnUpdateCommand="MyDataList_Update"
OnCancelCommand="MyDataList_Cancel" runat="server">

<ItemTemplate>

<table cellpadding=10 style="font: 10pt verdana">
<tr>
<td width=1 bgcolor="BD8672"/>
<td valign="top">
<img alt="book image" align="top" src='<%#
DataBinder.Eval(Container.DataItem, "title_id", "images/{0}.gif") %>' >
</td>
<td valign="top">
<b>Title: </b><%# DataBinder.Eval(Container.DataItem,
"title") %><br>
<b>Category: </b><%# DataBinder.Eval(Container.DataItem,
"type") %><br>
<b>Publisher ID: </b><%#
DataBinder.Eval(Container.DataItem, "pub_id") %><br>
<b>Price: </b><%# DataBinder.Eval(Container.DataItem,
"price", "$ {0}") %>
<p>
<asp:linkbutton CommandName="Edit" runat="server">
<img alt="edit book" border="0"
src="images/edit_book.gif" >
</asp:linkbutton>
</td>
</tr>
</table>

</ItemTemplate>

<EditItemTemplate>

<table cellpadding=10 style="font: 10pt verdana">
<tr>
<td width=1 bgcolor="BD8672"/>
<td valign="top">
<img alt="book image" align="top" src='<%#
DataBinder.Eval(Container.DataItem, "title_id", "images/{0}.gif") %>' >
</td>
<td valign="top">
<b>Title: </b><%# DataBinder.Eval(Container.DataItem,
"title") %><br>
<b>Category: </b><%# DataBinder.Eval(Container.DataItem,
"type") %><br>
<b>Publisher ID: </b><%#
DataBinder.Eval(Container.DataItem, "pub_id") %><br>
<b>Price: </b><input id="edit_price" type="text"
value='<%# DataBinder.Eval(Container.DataItem, "price", "$ {0}") %>'
runat="server"/>
<p>
<asp:linkbutton CommandName="Update" runat="server"><img
alt="update" border="0" src="images/update_book.gif" ></asp:linkbutton>
<asp:linkbutton CommandName="Cancel" runat="server"><img
alt="cancel" border="0" src="images/cancel_book.gif" ></asp:linkbutton>
</td>
</tr>
</table>

</EditItemTemplate>

</ASP:DataList>

<!-- #include virtual="footer.inc" -->

</form>

<div style="font: 10pt verdana;padding:0,15,15,15" id="Message"
runat="server"/>

</body>
</html>
================================================== ==

As you can see, they conveniently commented, "database update left out
for simplicity's sake...". This didn't make it too simple for me as I
now don't know how to update.

Can someone help me out by filling in the update code where they
commented it out? I have no idea.
================================================== ==

Sub MyDataList_Update(Sender As Object, E As DataListCommandEventArgs)

' database update left out for simplicity's sake...

Dim EditText As HtmlInputText
EditText = E.Item.FindControl("edit_price")

Message.InnerHtml = "Price Updated: " & EditText.Value
MyDataList.EditItemIndex = -1
PopulateList()
End Sub

================================================== ==

Thanks,
Jim
Sep 6 '06 #1
0 1135

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Brent Webster | last post by:
I have an asp page that is attached to database and I want to update the database when the window is closed. It is basically 5 text boxes wide by 8 text boxes high and these are all dynamically...
9
by: Carlos | last post by:
I'm responsible for the content in a call center's intranet site. There are approximately 600 pages on 7 sub-webs. I have access to the sub-webs, but I don't have access to the root web or web...
3
by: Douglas Buchanan | last post by:
Buttons don't work if form is opened on startup A2k If 'frmMain' is set to open by default at startup none of the buttons work. If 'frmMain' is opened from the database window then all the...
15
by: Paul T. RONG | last post by:
Hello, I am making a restaurant database (it is much more complicated than I thought before!), now it comes to the last stage and I come across a problem. I will explain it in detail. In a...
0
by: Nashat Wanly | last post by:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnaskdr/html/askgui06032003.asp Don't Lock Type Objects! Why Lock(typeof(ClassName)) or SyncLock GetType(ClassName) Is Bad Rico...
1
by: dln | last post by:
Hello all. I'm trying to find the right group to post this to and since it's a coding question (of sorts), hopefully this is the right place. I'm attempting to run an LDAP query to return the...
0
by: Samy | last post by:
Hi There, I am trying to trace the block of code which had adapter.update(dataset). The adapter has the insert, update and delete commands defined on them along with the select command. Is there a...
2
by: Ville Mattila | last post by:
Hi there, I will post my question to this group too bacause the .data group seems to be rather quiet. I've been playing with VB.NET and ADO for a week now and find the different data handling...
20
by: Wes Groleau | last post by:
I was doing update statements in SQL Server 2000. I have a table with over 16 million rows. It came from several hundred delimited text files, and two of the columns are file ID (int) and Line...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.