8 Answers, 1 is accepted
0
Accepted

Princy
Top achievements
Rank 2
answered on 12 Jan 2009, 12:34 PM
Hello,
You can try out the following code to hide the AddNewRecord button from the comand item:
cs:
Thanks
Princy.
You can try out the following code to hide the AddNewRecord button from the comand item:
cs:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) |
{ |
if (e.Item is GridCommandItem) |
{ |
GridCommandItem cmdItem = (GridCommandItem)e.Item; |
//To hide the add new record button |
Button btn1 = (Button)cmdItem.FindControl("AddNewRecordButton"); |
btn1.Visible = false; |
//To hide the image button |
LinkButton lnkbtn1 = (LinkButton)cmdItem.FindControl("InitInsertButton"); |
lnkbtn1.Visible = false; |
} |
} |
Thanks
Princy.
0

El
Top achievements
Rank 1
answered on 12 Jan 2009, 12:44 PM
Well i converted this code to VB.NET and i ended with the following code:
But, unfortunately i am getting an exception:
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Line 103: Dim btn1 As New Button
Line 104: btn1 = CType(cmdItem.FindControl("AddNewRecordButton"), Button)
Line 105: btn1.Visible = False
Line 106: 'To hide the image button Line
107: Dim lnkbtn1 As New LinkButton
So please tell me how do i fix this code
Thanks in advance
If e.Item.GetType Is GetType(GridCommandItem) Then |
Dim cmdItem As GridCommandItem = CType(e.Item, GridCommandItem) |
'To hide the link button |
Dim btn1 As Button = CType(cmdItem.FindControl("AddNewRecordButton"), Button) |
btn1.Visible = False |
'To hide the image button |
Dim lnkbtn1 As LinkButton = CType(cmdItem.FindControl("InitInsertButton"), LinkButton) |
lnkbtn1.Visible = False |
End If |
But, unfortunately i am getting an exception:
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Line 103: Dim btn1 As New Button
Line 104: btn1 = CType(cmdItem.FindControl("AddNewRecordButton"), Button)
Line 105: btn1.Visible = False
Line 106: 'To hide the image button Line
107: Dim lnkbtn1 As New LinkButton
So please tell me how do i fix this code
Thanks in advance
0

El
Top achievements
Rank 1
answered on 12 Jan 2009, 02:11 PM
This portion works just fine:
but the other one doesn't work. I suspect the cmdItem.FindControl("AddNewRecordButton") .. AddNewRecordButton seems right spelled but doesn't return any result with search.
Thanks
'To hide the image button |
Dim lnkbtn1 As LinkButton = CType(cmdItem.FindControl("InitInsertButton"), LinkButton) |
lnkbtn1.Visible = False |
but the other one doesn't work. I suspect the cmdItem.FindControl("AddNewRecordButton") .. AddNewRecordButton seems right spelled but doesn't return any result with search.
Thanks
0

Shinu
Top achievements
Rank 2
answered on 13 Jan 2009, 04:55 AM
Hi El,
Give a try with the following code snippet and see if it is working.
CS:
Thanks
Shinu.
Give a try with the following code snippet and see if it is working.
CS:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) |
{ |
if (e.Item is GridCommandItem) |
{ |
GridCommandItem cmdItem = (GridCommandItem)e.Item; |
Button btn1 = (Button)cmdItem.Controls[0].Controls[0].Controls[0].Controls[0].Controls[0]; |
btn1.Visible = false; |
} |
} |
Thanks
Shinu.
0

El
Top achievements
Rank 1
answered on 13 Jan 2009, 06:18 AM
It throws an exception:
Unable to cast object of type 'Telerik.Web.UI.GridLinkButton' to type 'System.Web.UI.WebControls.Button'
Then i declared btn1 as GridLinkButton but the intellisense underlined it alerting me that it's not accessible because it is friend. Any ideas?
Thanks
Unable to cast object of type 'Telerik.Web.UI.GridLinkButton' to type 'System.Web.UI.WebControls.Button'
Then i declared btn1 as GridLinkButton but the intellisense underlined it alerting me that it's not accessible because it is friend. Any ideas?
Thanks
0

Princy
Top achievements
Rank 2
answered on 13 Jan 2009, 06:28 AM
Hi,
Try accessing it as a LinkButton as shown below.
VB:
Princy
Try accessing it as a LinkButton as shown below.
VB:
Protected Sub RadGrid1_ItemDataBound(ByVal sender As Object, ByVal e As GridItemEventArgs) |
If TypeOf e.Item Is GridCommandItem Then |
Dim cmdItem As GridCommandItem = DirectCast(e.Item, GridCommandItem) |
Dim lnkbtn As LinkButton = DirectCast(cmdItem.Controls(0).Controls(0).Controls(0).Controls(0).Controls(0), LinkButton) |
lnkbtn.Visible = False |
End If |
End Sub |
Princy
0

El
Top achievements
Rank 1
answered on 13 Jan 2009, 07:01 AM
Don't you think that these both do the same .. hiding the LinkButton ?
I mean what is the difference. However, the find Control did the trick .. i don't see the AddNewRecord button anymore.
Thanks
Dim lnkbtn1 As LinkButton = DirectCast(cmdItem.FindControl("InitInsertButton"), LinkButton) |
lnkbtn1.Visible = False |
Dim btn1 As LinkButton = CType(cmdItem.Controls(0).Controls(0).Controls(0).Controls(0).Controls(0), LinkButton) |
btn1.Visible = False |
I mean what is the difference. However, the find Control did the trick .. i don't see the AddNewRecord button anymore.
Thanks
0

Olo
Top achievements
Rank 1
answered on 27 Feb 2009, 01:40 PM
Sorry, delete my post please.