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

Set a textbox visible or not depending a certain field

1 Answer 334 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Isabelle
Top achievements
Rank 1
Isabelle asked on 22 May 2014, 05:38 PM
Hi,

I add textbox in code-behind like that :
    Public Sub New(ByVal cName As String)
 
        colname = cName
 
    End Sub
    Public Sub InstantiateIn(ByVal container As System.Web.UI.Control) Implements ITemplate.InstantiateIn
 
        textBox = New TextBox()
        textBox.Width = 27
        container.Controls.Add(textBox)
        AddHandler textBox.DataBinding, AddressOf textValue_DataBinding
 
    End Sub
 
    Sub textValue_DataBinding(ByVal sender As Object, ByVal e As EventArgs)
 
        Dim MyTextBox As TextBox = DirectCast(sender, TextBox)
        Dim container As GridDataItem = DirectCast(MyTextBox.NamingContainer, GridDataItem)
        MyTextBox.Text = DirectCast((DirectCast(container.DataItem, DataRowView))(colname), Integer)
 
    End Sub
 
End Class

So, i would like that my textbox will be visible if another field of that datasource =1 and every texbox will be visible or not(not all). Thanks!

1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 23 May 2014, 05:38 AM
Hi Isabelle,

Please set the TextBox's ID property to access it and try the following code snippet.

VB:
txtName = New TextBox()
txtName.ID = "TxtName"
container.Controls.Add(txtName)
. . . . .
Protected Sub RadGrid1_ItemDataBound(sender As Object, e As Telerik.Web.UI.GridItemEventArgs)
    If TypeOf e.Item Is GridDataItem Then
        Dim dataItem As GridDataItem = DirectCast(e.Item, GridDataItem)
        'Find TextBox using its ID
        Dim txtName As TextBox = DirectCast(dataItem.FindControl("TxtName"), TextBox)
        'Condition check
        If True Then
            txtName.Visible = False
        End If
    End If
End Sub

Thanks,
Princy
Tags
Grid
Asked by
Isabelle
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Share this question
or