Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > Other .NET > General .NET
|
General .NET For general discussion of MICROSOFT .NET topics that don't fall within any of the other .NET forum subcategories or .NET language forums.  If your question is specific to a language (C# or Visual Basic) or type of application (Windows Forms or ASP.Net) try an applicable forum category. ** PLEASE BE SPECIFIC WITH YOUR QUESTION ** When posting here, provide details regarding the Microsoft .NET language you are using and/or what type of application (Windows/Web Forms, etc) you are working in, if applicable to the question. This will help others answer the question without having to ask.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the General .NET section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 2nd, 2004, 01:36 PM
Authorized User
 
Join Date: Aug 2004
Posts: 32
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to humour
Default TextBox.Text property returns only old value?

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

Code:
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>
 
Old August 2nd, 2004, 01:52 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Hey,

I think you want IsNothing and not IsDbNull. There is a big difference, being that DbNull is database-specific content, not for the textbox.

Anyway, your issue is you reference the wrong ID. The code:

Dim txtboxCust As TextBox = e.Item.Cells(0).FindControl("txtboxCustName")

Should be:

Dim txtboxCust As TextBox = e.Item.Cells(0).FindControl("txtboxcust_name")

Brian
 
Old August 2nd, 2004, 02:22 PM
Authorized User
 
Join Date: Aug 2004
Posts: 32
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to humour
Default

I actually just changed the code to make it more readable when I was posting the
topic. I compiled, checked, doublchecked and recompiled I
still have the same problem. Please if you have a moment take another look... I
edited my post to make the strings identical now.

Thanks for your help !

Humour
 
Old August 2nd, 2004, 03:30 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Hey,

Why do you use the ADODB.Recordset? Why not use the DataSet directly?

Dim objConnection As New OleDbConnection(strConnectionString)
Dim objAdapter As New OleDbDataAdapter("select query...", objConnection)
Dim objDataSet As New DataSet

'Don't need to open connection in disconnected environment
objAdapter.Fill(objDataSet, "tablename")

DataGrid1.Datasource = objDataSet.Tables(0).DefaultView
DataGrid1.DataBind()

Brian
 
Old August 2nd, 2004, 03:53 PM
Authorized User
 
Join Date: Aug 2004
Posts: 32
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to humour
Default

See my replies embedded in your quoted text.

Why do you use the ADODB.Recordset?
Because I am acessdata that from MAXDB (a product from MYSql). It does not have an OLD DB driver hence I use ADODB.

Why not use the DataSet directly?
Essentially I am this is what my code was...
' locDS is a variable of type dataset
DataGrid1.DataSource = locDS
' This is what I changed it to, still doesnt work, I think in my case
' the code would do the same thing no? I only have one table in
' the dataset
DataGrid1.DataSource = locDS.Tables(0).DefaultView


Thanks again for your help, I am STILL struggling with the OnUpdateCommand handler... Now even with a straight ODBC objecthandler.
 
Old August 2nd, 2004, 04:22 PM
Friend of Wrox
 
Join Date: Jul 2004
Posts: 623
Thanks: 0
Thanked 1 Time in 1 Post
Default

in this line
Dim txtboxCust As TextBox = e.Item.Cells(0).FindControl("txtboxcustname")
change it to
Dim txtboxCust As TextBox =CType(e.Item.FindControl("txtboxcustname"), TextBox).Text

--------------------------------------------
Mehdi.
 
Old August 2nd, 2004, 04:23 PM
Authorized User
 
Join Date: Aug 2004
Posts: 32
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to humour
Default

:):):):D:D:D
FINALLY --- I figured it out...whilst reading another thread on this site pertaining to DataGrids.

I was missing this important IF statement to qualify when I call my BindGrid method ----- Darn what an expensive lesson.


Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
     If Not Page.IsPostBack Then
            Call BindGrid()
     End If
End Sub

Thank you Brian and mehdi62b for your replies and assistance.
 
Old August 3rd, 2004, 02:59 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Quote:
quote:Originally posted by bmains
'Don't need to open connection in disconnected environment
Well, you do, it's just the DataAdapter classes do it for you automagically.
 
Old August 3rd, 2004, 03:14 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Quote:
quote:Originally posted by humour
Why do you use the ADODB.Recordset?
Because I am acessdata that from MAXDB (a product from MYSql). It does not have an OLD DB driver hence I use ADODB.
Presumably you are using ADODB.Recordset because you are using a ODBC connection to your data source? Why not use the System.Data.Odbc .NET classes?
 
Old August 3rd, 2004, 07:01 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

I should have said: Don't need to manually open connection in disconnected environment

I probably was typing in a hurry.

Thanks.

Quote:
quote:Originally posted by planoie
 
Quote:
quote:Originally posted by bmains
Quote:
'Don't need to open connection in disconnected environment
Well, you do, it's just the DataAdapter classes do it for you automagically.





Similar Threads
Thread Thread Starter Forum Replies Last Post
changing the backcolor property of the textbox Fehrer Access VBA 9 April 19th, 2016 10:59 AM
Text Box .text Property Displays conflicting Valus JPOhlman Visual Basic 2005 Basics 3 August 23rd, 2006 02:39 PM
basic textbox property bem2x Beginning VB 6 1 August 23rd, 2006 11:17 AM
Can't set text property of dynamic text box sreerajrs ASP.NET 1.0 and 1.1 Professional 1 May 31st, 2006 09:39 PM
How to set textbox property to readonly when text bekim Classic ASP Basics 1 July 12th, 2005 12:06 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.