Ticket Q334279
Visible to All Users

ASPxGridView - How to find a control in grid DataItemTemplate

created 14 years ago

Using server side, postback = true
Trying to disable a linkbutton in that row on databound when there is a specific condition
Tried various scenario without any success (including one which was posted in Q21314)
Linkbutton name: ButSelectDish, column name: Select, column no: 0 (first one)
Dim x, y, mproductid, icol As Integer
x = Me.ASPxGridView3.VisibleRowCount - 1
y = 0
icol = 0
mproductid = 1
For y = 0 To x
           'the following works ok
            Dim iproductid As Integer = Me.ASPxGridView3.GetRowValues(y, "ProductId")
           'the following not working
            Dim islct As String = Me.ASPxGridView3.GetRow(y, "Select")
            Dim ilbl As LinkButton = CType(Me.ASPxGridView3.FindRowCellTemplateControl(y, Nothing, "ButSelectDish"), LinkButton)
            Dim ilbl2 As LinkButton = CType(Me.ASPxGridView3.FindRowTemplateControl(y, "ButSelectDish"), LinkButton)
            ilbl.Enabled = False
Next
What would be the equivalent in normal asp grid:
dim ilbl as linkbutton = ctype(me.gridview.row(y).findcontrol("ButSelectDish"),linkbutton)
What is, if any the code, to get that linkbutton within the row?
Thank you

Show previous comments (6)
PM PM
Patricia Marchand 1 14 years ago

    Once again, I am afraid, your answer is beside the point.
    All the fields are templates as you can see from the small codes I have taken the bother to put in my last reply.
    Just want to know what is the code to use with your aspxgridview component in the databound to get the control row after row as below suggest:
    Protected Sub ASPxGridView1_DataBound(sender As Object, e As System.EventArgs) Handles ASPxGridView1.DataBound
            Dim x, y As Integer
            y = 0
            x = Me.ASPxGridView1.VisibleRowCount - 1
            For y = 0 To x
                'what are the codes, server side for the following:
                'Dim ilabel As label = CType(Me.ASPxGridView1.Row(y).findcontrol("lblCategory"),label)
                'dim ilinkbuton as linkbutton = CType(Me.ASPxGridView1.Row(y).findcontrol("butselect"),linkbutton)
                'if ilabel.text = "Choosen words" then
                ' ilinkbutton.visible = true
                'else
                ' ilinkbutton.visible = false
                'end if
            Next
        End Sub

    PM PM
    Patricia Marchand 1 14 years ago

      I am really getting annoyed now, you are always answering beside the point. Please read the question I have raised before answering. If the codes do not exist and therefore I cannot get at the control within your component just say so. We cannot carry working like this, we are very busy and we need an answer!
      Patricia Marchand

      DevExpress Support Team 14 years ago

        Hello Patricia,
        Please accept my sincere apologies for disappointing you. I have prepared a sample project to demonstrate what I meant in my previous posts (see the attachment). Here you will see four ASPxGridView controls. ASPxLabel is located in different ASPxGridView templates. Thus, I have shown four different techniques how to find and hide the label based on a template container.

        1. ASPxLabel is located inside the DataItemTemplate. I have used the ASPxGridView.FindRowCellTemplateControl method:
        Visual Basic
        Protected Sub ASPxGridView1_DataBound(sender As Object, e As System.EventArgs) Handles ASPxGridView1.DataBound Dim y As Integer = 0 Dim x As Integer = Me.ASPxGridView1.VisibleRowCount - 1 For y = 0 To x Dim ilabel As ASPxLabel = CType(Me.ASPxGridView1.FindRowCellTemplateControl(y, Nothing, "lblCategory"), ASPxLabel) If ASPxGridView1.GetRowValues(y, "CategoryName").ToString() = "Confections" Then ilabel.ClientVisible = False End If Next End Sub
        1. ASPxLabel is located inside the DataRow Template. I have used the ASPxGridView.FindRowTemplateControl method:
        Visual Basic
        Dim ilabel As ASPxLabel = CType(Me.ASPxGridView2.FindRowTemplateControl(y, "lblCategory"), ASPxLabel)
        1. ASPxLabel is located inside the PreviewRow Template. In this case, I have used the FindPreviewRowTemplateControl method:
        Visual Basic
        Dim ilabel As ASPxLabel = CType(Me.ASPxGridView3.FindPreviewRowTemplateControl(y, "lblCategory"), ASPxLabel)
        1. I have illustrated how to use the Init/Load technique that is described in the K18282 KB article (The general technique of using the Init/Load event handler):
        Visual Basic
        Protected Sub ASPxLabel1_Load(sender As Object, e As System.EventArgs) Dim ilabel As ASPxLabel = TryCast(sender, ASPxLabel) Dim container As GridViewDataItemTemplateContainer = TryCast(ilabel.NamingContainer, GridViewDataItemTemplateContainer) If (container.VisibleIndex \ 2 = 0) Then ilabel.ClientVisible = False End If End Sub

        As you can see, the last approach is the easiest because it does not require a loop through all grid rows. Thus, I suggest that you are using this solution in your scenario.
        In addition, I would like to note that ASPxGridView quite differs from the asp:GridView control. Solutions you used for asp:GridView may be not suitable for ASPxGridView. Thus, the same scenario may be utilized by using different asp and ASPx grid approaches. If none of the mentioned approaches suits your requirements, please let us know and describe them in greater detail. We will be happy to help you understand our controls better.
        Thanks,
        Marion

        Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

        Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.