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

Get value of template column

1 Answer 109 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Salman
Top achievements
Rank 1
Salman asked on 03 Oct 2011, 11:59 AM
hi people
I have a grid which add template cloumn in code behind .my code  is here

 

 

If Not tblLastItem.Rows(i)("CntrGnlItm_Level") Then

 

dtbl.Columns.Add(tblLastItem.Rows(i)(

 

"CntrLstItm_ID_").ToString)

 

 

 

Dim templateColumnName As String = tblLastItem.Rows(i)("CntrLstItm_ID_")

 

 

 

Dim templateColumn As New GridTemplateColumn()

 

templateColumn.ItemTemplate =

 

New MyEditTemplate(templateColumnName)

 

templateColumn.EditItemTemplate =

 

New MyEditTemplate(templateColumnName)

 

templateColumn.HeaderText = tblLastItem.Rows(i)(

 

"CntrGnlItm_ParentTitr").ToString.Trim + "--" + tblLastItem.Rows(i)("CntrLstItm_Titr").ToString.Trim

 

templateColumn.UniqueName = tblLastItem.Rows(i)(

 

"CntrLstItm_ID_")

 

 

 

Me.grd.MasterTableView.Columns.Add(templateColumn)

 

 

 

Else

 

 

 

If Not Me.grd2.MasterTableView.Columns.Contains(tblLastItem.Rows(i)("CntrLstItm_ID_").ToString) Then

 

 

 

Me.grd2.MasterTableView.Columns.Add(col)

 

 

 

End If

 

dtbl2.Columns.Add(tblLastItem.Rows(i)(

 

"CntrLstItm_ID_").ToString)

 

 

 

End If

 

so,there is a RadNumericTextBox in  MyEditTemplate .User enter value in RadNumericTextBox ,How i get value which user entered?

1 Answer, 1 is accepted

Sort by
0
Andrey
Telerik team
answered on 06 Oct 2011, 12:19 PM
Hello Salman,

In order to access the RadNumericTextBox inside template column, you should hook the Item_DataBound event of RadGrid and in its body to check for the appropriate type of item. After this condition is satisfied you should proceed by casting the item to the this type. Next  use FindControl method to find the needed control based on its server ID, after that you could get the value.

The following code snippet shows one way for achieving this:
Protected Sub RadGrid1_ItemDataBound(sender As Object, e As GridItemEventArgs) Handles RadGrid1.ItemDataBound
    If TypeOf e.Item Is GridEditableItem AndAlso e.Item.IsInEditMode Then
        Dim item As GridEditableItem = TryCast(e.Item, GridEditableItem)
        Dim radNumericTextBox As RadNumericTextBox = TryCast(item("CntrLstItm_ID_").FindControl("RadNumericTextBox_ID"), RadNumericTextBox)
        Dim value As System.Nullable(Of Double) = radNumericTextBox.Value
    End If
End Sub

Best wishes,
Andrey
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
Tags
Grid
Asked by
Salman
Top achievements
Rank 1
Answers by
Andrey
Telerik team
Share this question
or