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
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