humour
Programmer
- Nov 24, 2003
- 87
language: VB.NET
database: MaxDB published by MySQL (this is not a MySql database it is different).
version: v1.1.4322 (does this make sense, I took it from the folder name located on my server here: \\server\winnt\Microsoft.Net\Framework
Database Connection: Imports ADODB or ADODB
The problem in a nutshell is this. I can successfully get a handle to a TextBox control in my DataGrid.OnpdateCommand handler but when I reference the property it is only the OLD value and not the changed value.
No exageration here I have literally spent 15 hours trying to solve this darn problem. I would sincerely appreciate any help.
I am trying to get the changed value of TextBox.Text within a datagrid.OnUpdateCommand handler implemented within the [EditTemplate]tags of a [TemplateColumn].
Customer.Aspx.VB
Sub DataGrid1_UpdateCommand(ByVal source As Object, ByVal e As DataGridCommandEventArgs) Handles DataGrid1.UpdateCommand
Dim txtboxCust As TextBox = e.Item.Cells(0).FindControl("txtboxcustname")
' Tests that the handle is actually a reference to what I think it is
txtboxCust.Visible = False
txtboxCust.ToolTip = txtboxCust.Text
If Not (IsDBNull(txtboxCust)) Then
' This line executes but doesnt show me my edited text .. WHY NOT !!!!!
Response.Write("not null " & txtboxCust.Text)
Else
Response.Write("is is null")
End If
End Sub
'I dont think this is a relevant but I included it in case it may be this is my BindGrid Method that takes the adodb.recordset and assigns it to a dataset which than becomes the source for my datagrid
Customer.Aspx
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Call BindGrid()
End Sub
Sub BindGrid()
Dim locDS As New DataSet
Dim lOleDBadp As New OleDbDataAdapter
Dim CustName As String
Dim contADO As New ADODB.Connection
Dim contRS As New ADODB.Recordset
Dim flds As ADODB.Fields
contADO.ConnectionString = "dsn=contact;user id=CM;password=?????;"
contADO.Open()
contRS.Open("select id, cust_name from customers where cust_no = '9908' ", contADO, CursorTypeEnum.adOpenDynamic)
' The next 2 lines fill my dataset and assigns it to my datagrid
lOleDBadp.Fill(locDS, contRS, "custs")
DataGrid1.DataSource = locDS
DataGrid1.DataBind()
contADO.Close()
End Sub
Customer.ASPX
<body>
<form id="Form1" method="post" runat="server">
<asp:datagrid id="DataGrid1" runat="server" OnEditCommand="DataGrid1_EditCommand" AutoGenerateColumns="False"
OnUpdateCommand="DataGrid1_UpdateCommand">
<Columns>
<asp:EditCommandColumn ButtonType="LinkButton" UpdateText="Upd" CancelText="" EditText="Edit"></asp:EditCommandColumn>
<asp:TemplateColumn>
<ItemTemplate>
<asp:Label Runat="server" ID="lblCustName" Text='<%# DataBinder.Eval (Container.DataItem,"cust_name") %>' />
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox Runat="server" ID="txtboxcustname" Text='<%# DataBinder.Eval (Container.DataItem,"cust_name") %>' />
</EditItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:datagrid></form>
</body>
database: MaxDB published by MySQL (this is not a MySql database it is different).
version: v1.1.4322 (does this make sense, I took it from the folder name located on my server here: \\server\winnt\Microsoft.Net\Framework
Database Connection: Imports ADODB or ADODB
The problem in a nutshell is this. I can successfully get a handle to a TextBox control in my DataGrid.OnpdateCommand handler but when I reference the property it is only the OLD value and not the changed value.
No exageration here I have literally spent 15 hours trying to solve this darn problem. I would sincerely appreciate any help.
I am trying to get the changed value of TextBox.Text within a datagrid.OnUpdateCommand handler implemented within the [EditTemplate]tags of a [TemplateColumn].
Customer.Aspx.VB
Sub DataGrid1_UpdateCommand(ByVal source As Object, ByVal e As DataGridCommandEventArgs) Handles DataGrid1.UpdateCommand
Dim txtboxCust As TextBox = e.Item.Cells(0).FindControl("txtboxcustname")
' Tests that the handle is actually a reference to what I think it is
txtboxCust.Visible = False
txtboxCust.ToolTip = txtboxCust.Text
If Not (IsDBNull(txtboxCust)) Then
' This line executes but doesnt show me my edited text .. WHY NOT !!!!!
Response.Write("not null " & txtboxCust.Text)
Else
Response.Write("is is null")
End If
End Sub
'I dont think this is a relevant but I included it in case it may be this is my BindGrid Method that takes the adodb.recordset and assigns it to a dataset which than becomes the source for my datagrid
Customer.Aspx
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Call BindGrid()
End Sub
Sub BindGrid()
Dim locDS As New DataSet
Dim lOleDBadp As New OleDbDataAdapter
Dim CustName As String
Dim contADO As New ADODB.Connection
Dim contRS As New ADODB.Recordset
Dim flds As ADODB.Fields
contADO.ConnectionString = "dsn=contact;user id=CM;password=?????;"
contADO.Open()
contRS.Open("select id, cust_name from customers where cust_no = '9908' ", contADO, CursorTypeEnum.adOpenDynamic)
' The next 2 lines fill my dataset and assigns it to my datagrid
lOleDBadp.Fill(locDS, contRS, "custs")
DataGrid1.DataSource = locDS
DataGrid1.DataBind()
contADO.Close()
End Sub
Customer.ASPX
<body>
<form id="Form1" method="post" runat="server">
<asp:datagrid id="DataGrid1" runat="server" OnEditCommand="DataGrid1_EditCommand" AutoGenerateColumns="False"
OnUpdateCommand="DataGrid1_UpdateCommand">
<Columns>
<asp:EditCommandColumn ButtonType="LinkButton" UpdateText="Upd" CancelText="" EditText="Edit"></asp:EditCommandColumn>
<asp:TemplateColumn>
<ItemTemplate>
<asp:Label Runat="server" ID="lblCustName" Text='<%# DataBinder.Eval (Container.DataItem,"cust_name") %>' />
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox Runat="server" ID="txtboxcustname" Text='<%# DataBinder.Eval (Container.DataItem,"cust_name") %>' />
</EditItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:datagrid></form>
</body>