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

Can't FindConrtrol in Radgrid

3 Answers 48 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Rimantas
Top achievements
Rank 1
Rimantas asked on 23 Sep 2008, 07:55 AM
Hi,

I have dynamical RadGrid, GridTemplateColumn is making by MyTemplate class:
Public Class MyTemplate 
    Implements ITemplate 
    Protected boolValue As CheckBox 
    Protected tBox As TextBox 
    Private colname As String 
    Private isHeader As Boolean 
    Private columnId As String 
 
    Public Sub New(ByVal cName As StringByVal header As BooleanByVal id As String
        MyBase.New() 
        colname = cName 
        isHeader = header 
        columnId = id 
    End Sub 
 
    Public Sub InstantiateIn(ByVal container As System.Web.UI.Control) Implements ITemplate.InstantiateIn 
        If isHeader Then 
            boolValue = New CheckBox 
            boolValue.ID = colname.ToString 
            boolValue.Text = colname 
            boolValue.Enabled = True 
            boolValue.AutoPostBack = True 
            boolValue.Checked = True 
            container.Controls.Add(boolValue) 
        Else 
            boolValue = New CheckBox 
            boolValue.ID = columnId 
            AddHandler boolValue.DataBinding, AddressOf Me.boolValue_DataBinding 
            boolValue.Enabled = True 
            boolValue.Checked = False 
            tBox = New TextBox 
            AddHandler tBox.DataBinding, AddressOf Me.tBox_DataBinding 
            container.Controls.Add(boolValue) 
            container.Controls.Add(tBox) 
        End If 
    End Sub 
End Class 

Columns create code:
For Each row As DataRow In Services_Table.Rows 
    Dim templatecolumn As New GridTemplateColumn 
    templatecolumn.UniqueName = row(0) 
    templatecolumn.HeaderTemplate = New BeSkaitikliuTemplate(row(1), True, row(0)) 
    templatecolumn.ItemTemplate = New BeSkaitikliuTemplate(row(1), False, row(0)) 
    PriskirimasRadGrid.Columns.Add(templatecolumn) 
Next 
 

There I try to FindControl.

For Each GridColumn As GridColumn In PriskirimasRadGrid.MasterTableView.Columns 
    For Each item As GridDataItem In PriskirimasRadGrid.MasterTableView.Items 
    Dim cBox As CheckBox = CType(item.FindControl(GridColumn.UniqueName), CheckBox) 
    Next 
Next 

Can anybody help me?

3 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 23 Sep 2008, 10:10 AM
Hello Rimantas,

Try accessing the control as shown in the code snippet below
cs:
Dim cBox As CheckBox = DirectCast(item("ColumnUniqueName").FindControl("ControlID"), CheckBox) 

Thanks,
Princy.
0
Rimantas
Top achievements
Rank 1
answered on 23 Sep 2008, 10:38 AM
Thank for answer Princy,

I found that I can find control after RadGrid bind, but when I press submit button like this code

Protected Sub AtgalButton_Click(ByVal sender As ObjectByVal e As System.EventArgs) Handles AtgalButton.Click 
        For Each item As GridDataItem In PriskirimasRadGrid.MasterTableView.Items 
            Dim cBox As CheckBox = DirectCast(item("ColumnUniqueId").FindControl("ControlId"), CheckBox) 
        Next 
        Response.Redirect("~/Main/paslaugos.aspx"
    End Sub 

can't find control. What could be?
0
Rimantas
Top achievements
Rank 1
answered on 24 Sep 2008, 05:17 AM
I solved my problem.

Thanks Princy for your help.
Tags
Grid
Asked by
Rimantas
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Rimantas
Top achievements
Rank 1
Share this question
or