EditItemTemplate not showing on first click

J

Jim in Arizona

Using a datalist, I have an ItemTemplate and an EditItemTemplate.

The default view shows several records within the ItemTemplate based on
a basic SELECT statement. When the user presses the Edit button on an
item, then they should be taken to the EditItemTemplate.

When the Edit button is pressed, it calls on a different SQL statement
to only show populate the datalist with only the record the chose. This
works fine when they click the top item, but if they click on any item
below that, only one record is shown, which is as intended, but its
still in its ItemTemplate view, not the EditItemTemplate view. When I
click the update again on the record that is showing, it then goes to
its EditItemTemplate view. Although this is functional, its not doing as
its intended and is, at least, somewhat annoying.

Here my code (the parts I think would be relevant).

This is called when the page is loaded and whenever a button is pressed.
But, when the Edit button is pressed, a slightly different SQL statement
is used instead of the one in this Sub Procedure.

Sub PopulateList(ByVal sql As String)
Dim strSQLRead As String
strSQLRead = "SELECT ID, empname, supervisor, location,
roomarea, department, " & _
"request, dtrequest, dtsupapprove, supnote,
assignto, assigndenynote, " & _
"dtassign, priority, prioritycolor, adassignby,
prioritynumber " & _
"FROM TWorkRequest WHERE approvedeny=1 ORDER BY
prioritynumber, dtassign"

If sql = "" Then sql = strSQLRead

Dim DS As DataSet
Dim objConnection As SqlConnection
Dim objDataAdapter As SqlDataAdapter

objConnection = New
SqlConnection(ConfigurationManager.AppSettings("maintenance"))
objDataAdapter = New SqlDataAdapter(sql, objConnection)
DS = New DataSet
objDataAdapter.Fill(DS, "TWorkRequest")
dlRequests.DataSource = DS.Tables("TWorkRequest").DefaultView
dlRequests.DataBind()

End Sub

This is the sub that is called when the press the edit button. As you
can see, the SQL statement is only doing a SELECT where the ID of the
datarow from the database = the record they click on.

Sub EditRequest(ByVal sender As Object, ByVal e As
DataListCommandEventArgs)

Dim TKEY As String = dlRequests.DataKeys(e.Item.ItemIndex)

Dim strSQLRead As String

strSQLRead = "SELECT ID, empname, supervisor, location,
roomarea, department, " & _
"request, dtrequest, dtsupapprove, supnote, assignto,
assigndenynote, " & _
"dtassign, priority, prioritycolor, adassignby, prioritynumber
" & _
"FROM TWorkRequest WHERE ID =" & TKEY

dlRequests.EditItemIndex = CInt(e.Item.ItemIndex)

PopulateList(strSQLRead)

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,982
Messages
2,570,189
Members
46,735
Latest member
HikmatRamazanov

Latest Threads

Top