This is a migrated thread and some comments may be shown as answers.

TxtBox client/server side

2 Answers 94 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jocelyn
Top achievements
Rank 1
Jocelyn asked on 06 Feb 2012, 05:42 PM
Hi everybody,

I am desperate now... I MUST understand something...

I have a grid with some data Bind to a DataTable. Here is my ItemDataBound Event (column4 is the GridBoundColumn's UniqueName):

Protected Sub gridAllergies_ItemDataBound(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridItemEventArgs) Handles gridAllergies.ItemDataBound
        If (TypeOf e.Item Is GridEditableItem AndAlso CType(e.Item, GridEditableItem).IsInEditMode) Then
            Dim editedItem As GridEditableItem = CType(e.Item, GridEditableItem)
            Dim allergie As clsAllergie = CType(CType(e.Item.DataItem, DataRowView).Row, clsAllergie)
            Dim editor As GridDropDownListColumnEditor = CType(editedItem.EditManager.GetColumnEditor("column7"), GridDropDownListColumnEditor)
            editor.DataSource = ExecuteSql("Select '' as gral_numero ,'' as gral_description union all Select gral_numero, gral_description " & _
                                              " from phfgrall where pram_sequence = " + GetStr(GSite_phfgrall) + " order by gral_description").Tables(0).DefaultView
            editor.DataBind()
            Dim txtbx As TextBox = CType(editedItem("column4").Controls(0), TextBox)
            If Not allergie.NoGroupe = "" Then
                editor.SelectedValue = allergie.NomGroupe
            End If
 
            Dim update As LinkButton = CType(editedItem.FindControl("UpdateButton"), LinkButton)
            If (update IsNot Nothing) Then
                update.Attributes.Add("onclick", "return Validate('" + txtbx.ClientID + "')")
            End If
        End If
    End Sub

Where I want you to look is the last part "update.Attributes.Add("onclick""return Validate('" + txtbx.ClientID + "')")"

Now let's see my JS function:

function Validate(txt)
 {
         var txtbx = document.getElementById(txt)
          alert(txtbx.value);
          return true
 }

So you can see that the only things this is doing is showing the value of the textbox after clicking on Update. This work fine! Example: If the current value is "toto" and I change it to "tata" and press Update, it will show "tata".

After that, it fire the update event and enter in the UpdateCommand event. So here is my code:

Protected Sub gridAllergies_UpdateCommand(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles gridAllergies.UpdateCommand
    Dim editItem As GridEditableItem = TryCast(e.Item, GridEditableItem)
    Dim txtbx As TextBox = CType(editItem("column4").Controls(0), TextBox)
    Debug.WriteLine(txtbx.Text)
End Sub

The thing I CAN'T understand is why txtbx.Text is equal to "toto" instead of "tata" ?

I'm on that since 2 days ago and now I don't know what to do to get the new value...

I hope someone will be able to tell me why this is happening.

2 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 07 Feb 2012, 08:26 AM
Hello,

I have tried to reproduce the issue but  no avail. Here is the sample code I have tried.
VB:
Protected Sub RadGrid1_UpdateCommand(sender As Object, e As GridCommandEventArgs)
 
    Dim item As GridEditableItem = DirectCast(e.Item, GridEditableItem)
    Dim txt As TextBox = DirectCast(item("ContactTitle").Controls(0), TextBox)
    Dim newValues As New Hashtable()
    e.Item.OwnerTableView.ExtractValuesFromItem(newValues, item)
    Dim id As String = newValues("ContactTitle").ToString()
    Response.Write(id)
 
End Sub
Also take a look into the following documentation for more.
Retrieving Original Values for Edited Item

Thanks,
Princy.
0
Jocelyn
Top achievements
Rank 1
answered on 07 Feb 2012, 06:01 PM
Here is my mistake....

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    RadGrid1.DataSource = CurrentPatient.Allergies
    RadGrid1.DataBind()
End Sub

I move that in NeedDataSource and I can get my modified data... Thanks for your help!
Tags
Grid
Asked by
Jocelyn
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Jocelyn
Top achievements
Rank 1
Share this question
or