Problems with HtmlControls.HtmlInputText & datalist Update

J

Jim in Arizona

I'm trying to do a simple update of data but I can't get the code right.

It's a datalist control that has the update/cancel/delete subroutines.

Here's the broken down datalist aspx code (just the EditItemTemplate part):


<EditItemTemplate>
<table cellpadding="10" style="font: 12PT Bookman Old Style">
<tr>
<td><b>Name:</b><input id="edit_name" type="text"
value='<%#DataBinder.Eval(Container.DataItem, "name")%>' runat="server"
/></td>
</tr>
<tr>
<td>
<asp:Button ID="button2" CommandName="Update" runat="server"
Text="Update" />
<asp:Button id="button3" CommandName="Cancel" runat="server"
Text="Cancel" />
</td>
</tr>
</table>
</EditItemTemplate>

And here's my update command subroutine:

Sub DL1_Update(ByVal sender As Object, ByVal e As
DataListCommandEventArgs)
Dim TKEY As String

TKEY = DL1.DataKeys(e.Item.ItemIndex)

Dim test As String =
e.Item.FindControl("edit_name").Controls.ToString
test = e.Item.FindControl("edit_name").ToString

Dim test2 As System.Web.UI.HtmlControls.HtmlInputText
test2 = e.Item.FindControl("edit_name")

Dim SQL As String
SQL = "UPDATE phonetest SET name = '" & test2.ToString & "'
WHERE ID = " & TKEY
Dim objConnection As SqlConnection
objConnection = New
SqlConnection(ConfigurationManager.AppSettings("tests"))
Dim objCommand As New SqlCommand(SQL, objConnection)
objConnection.Open()
objCommand.ExecuteNonQuery()
objConnection.Close()

DL1.EditItemIndex = -1
PopulateList()
End Sub

I've tried both test and test2 (see code above) for the text part of my
update sql statement. However, it doesn't appear to matter. The only
thing that actually get sent back to the server is this text:

System.Web.UI.HtmlControls.HtmlInputText

When I click update, the text above is what gets written to the table
instead of whatever it is I type.

So, I just need to know how to set the text I type into the text box
into a variable so I can place that into my SQL text.

TIA,
Jim
 

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

Forum statistics

Threads
473,754
Messages
2,569,527
Members
44,998
Latest member
MarissaEub

Latest Threads

Top