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
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.
Hello Patricia,
Thank you for the report. I see you want to disable LinkButton depending on some conditions. I think you can use a simple solution based on the The general technique of using the Init/Load event handler KB article.
You can handle the LinkButton.Init (Load) event in the following manner:
protected void ButSelectDish_Load (Object sender, EventArgs e) { LinkButton link = sender as LinkButton; link.Enabled = false; }
Thanks,
Vest
No this is not what I meant.
I am trying to make the linkbutton visible/not visible on the aspxgridview databound.
Just cannot find the code to get the row, the example I showed you is made with normal asp.net in VB and within the grid databound, not the click.
Hello Patricia,
Would you please clarify where ButSelectDish is located? Each ASPxGridView provides its own method to find a control inside it. So, we cannot provide you with an answer until you specify the template container.
In any case, as Vest, I suggest that you handle the ButSelectDish_Load event. Here, you will be able to refer to the row and its values by using the NamingContainer property. To learn more about this approach, please review the The general technique of using the Init/Load event handler KB article.
Thanks,
Marion
Would you like to answer to my question or not?
I am looking for the codes to run in the databind of an aspxgridview, server side.
Codes which would be along those lines, if I was to coded using the normal asp.net
dim x, y as integer
y = 0
x = me.gridview.rows.count -1
for y = 0 to x
dim ilbl as label = ctype(me.gridview.rows(y).findcontrol("lblid"),label)
if whatever condition I need then
ilbl.visible = false
end if
next y
Looking for the codes for your components to replace the ctype(me.gridview.rows(y).findcontrol("lblid"),label) of the normal asp.net codes which would be placed in the data bind of the grid
which I cannot obviously invente.
I tried the asp.net codes but they do not work with your components.
It does not matter where the linkbutton is located, as it happens it is in a template field of an aspxgridview. Just looking for the codes to get the controls on the databind of the aspxgridview.
Looking for the aspxgridview component server side code to get the controls on databound.
Example of what I am looking for (the following codes do work with a normal asp.net grid but not with your aspxgridview component):
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
Patricia,
I am afraid, the FindControl method does not work for ASPxGridView. It is necessary to use particular template methods. For example:
the ASPxGridView.FindDetailRowTemplateControl method searches for the server control contained within the specified detail row's template;
the method searches for the specified server control contained within the Edit Form's template;
the ASPxGridView.FindRowCellTemplateControl method searches for the server control contained within the specified data cell's template;
the ASPxGridView.FindRowTemplateControl method searches for the specified server control contained within the specified data row's template.
Would you please clarify which template you are using? This will help us put you on the right track.
Thanks,
Marion
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
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
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.
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
Dim ilabel As ASPxLabel = CType(Me.ASPxGridView2.FindRowTemplateControl(y, "lblCategory"), ASPxLabel)
Dim ilabel As ASPxLabel = CType(Me.ASPxGridView3.FindPreviewRowTemplateControl(y, "lblCategory"), ASPxLabel)
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