I am switching over a gridview to a radgrid and ran into a hiccup, Gridview when a cell is blank actually puts in a so you have to check for this , apparently Radgrid works differently. I am trying to find out if a cell is blank or not, if its blank I want to hide a button on the radgrid.
Protected Sub myRadGrid_ItemDataBound(sender As Object, e As Telerik.Web.UI.GridItemEventArgs) Handles myRadGrid.ItemDataBound
If (TypeOf e.Item Is GridDataItem) Then
Dim button As LinkButton = e.Item.FindControl("lnkPickUp")
Dim text As String = e.Item.Cells(7).Text
If text = Nothing Then
button.Enabled = False
button.Visible = False
End If
End If
End Sub
6 Answers, 1 is accepted
0

Shinu
Top achievements
Rank 2
answered on 27 Mar 2012, 05:46 AM
Hello Kevin,
You can check for null value with the following code.
VB:
Thanks,
Shinu.
You can check for null value with the following code.
VB:
Protected
Sub
grid1_ItemDataBound(sender
As
Object
, e
As
Telerik.Web.UI.GridItemEventArgs)
If
TypeOf
e.Item
Is
GridDataItem
Then
Dim
itm
As
GridDataItem =
DirectCast
(e.Item, GridDataItem)
Dim
link
As
LinkButton =
DirectCast
(itm.FindControl(
"lnkPickUp"
), LinkButton)
Dim
text
As
String
= e.Item.Cells(2).Text
If
text =
" "
Then
link.Visible =
False
End
If
End
If
End
Sub
Thanks,
Shinu.
0

Kevin
Top achievements
Rank 1
answered on 27 Mar 2012, 02:10 PM
Hi,
I originally tried this as that is how it is in a gridview, but its not working, nothing changed but changing to a radgrid, i have tried the following.
If IsDBNull(text) Then
if text = " " then
if text = " " then
I checked my sql query and it comes into the grid a a null.
I originally tried this as that is how it is in a gridview, but its not working, nothing changed but changing to a radgrid, i have tried the following.
If IsDBNull(text) Then
if text = " " then
if text = " " then
I checked my sql query and it comes into the grid a a null.
0

Shinu
Top achievements
Rank 2
answered on 28 Mar 2012, 01:10 PM
Hello Kevin,
Can you please specify the ColumnType you are using(means column which has Cell index 7)? Please note that columns like GridDateTimeColumn,GridButtonColumn etc are rendered as their respective controls in normal mode. Please post your code for more help.
Thanks,
Shinu.
Can you please specify the ColumnType you are using(means column which has Cell index 7)? Please note that columns like GridDateTimeColumn,GridButtonColumn etc are rendered as their respective controls in normal mode. Please post your code for more help.
Thanks,
Shinu.
0

Kevin
Top achievements
Rank 1
answered on 28 Mar 2012, 01:58 PM
Hi,
its just a gridboundcoulmn
<telerik:GridBoundColumn DataField="name" HeaderText="ISSUED TO" />
its just a gridboundcoulmn
<telerik:GridBoundColumn DataField="name" HeaderText="ISSUED TO" />
<
Columns
>
<
telerik:GridTemplateColumn
HeaderText
=
"Return"
>
<
ItemTemplate
>
<
asp:LinkButton
ID
=
"lnkReturn"
runat
=
"server"
CommandArgument='<%# bind("intRecId") %>' ToolTip="Return To Individual" CommandName="Return"
OnClientClick="return confirm('Are you sure you want to return item to service and Owner');"><
asp:Image
ID
=
"imgReturn"
runat
=
"server"
ImageUrl
=
"~/Images/Return.png"
BorderStyle
=
"None"
/></
asp:LinkButton
>
</
ItemTemplate
>
</
telerik:GridTemplateColumn
>
<
telerik:GridTemplateColumn
HeaderText
=
"ReIssue"
>
<
ItemTemplate
>
<
asp:LinkButton
ID
=
"lnkPickUp"
runat
=
"server"
CommandArgument='<%# bind("intRecId") %>' ToolTip="ReIssue to other person picking up equipment" CommandName="Pickup"
OnClientClick="return confirm('Are you sure you want to return issue item to another person');"><
asp:Image
ID
=
"imgReIssue"
runat
=
"server"
ImageUrl
=
"~/Images/ReIssue.png"
BorderStyle
=
"None"
/></
asp:LinkButton
>
</
ItemTemplate
>
</
telerik:GridTemplateColumn
>
<
telerik:GridTemplateColumn
HeaderText
=
"INFO"
>
<
ItemTemplate
>
<
asp:Image
ID
=
"imgLooker"
runat
=
"server"
ImageUrl
=
"~/Images/ViewResources.gif"
ImageAlign
=
"Middle"
BorderStyle
=
"None"
/>
<
asp:PopupControlExtender
ID
=
"popInfo"
runat
=
"server"
PopupControlID
=
"pnlPop"
TargetControlID
=
"imgLooker"
DynamicContextKey='<% #Eval("intRecId") %>'
DynamicControlID="pnlpop" DynamicServiceMethod="HelloWorld" Position="bottom"></
asp:PopupControlExtender
>
</
ItemTemplate
>
</
telerik:GridTemplateColumn
>
<
telerik:GridBoundColumn
DataField
=
"SN"
HeaderText
=
"SN"
/>
<
telerik:GridBoundColumn
DataField
=
"strManufacturer"
HeaderText
=
"MANUFACTURER"
/>
<
telerik:GridBoundColumn
DataField
=
"strModel"
HeaderText
=
"MODEL"
/>
<
telerik:GridBoundColumn
DataField
=
"strMake"
HeaderText
=
"MAKE"
/>
<
telerik:GridBoundColumn
DataField
=
"name"
HeaderText
=
"ISSUED TO"
/>
</
Columns
>
0
Accepted

Shinu
Top achievements
Rank 2
answered on 29 Mar 2012, 09:03 AM
Hello Kevin,
The column index starts at index 2 beacuse GridExpandColumn and GridRowindicatorColumn are always in front of data columns.
If you are accessing using cell index then the "Name" column should have an index of 9. Otherwise you can set a UniqueName for the column and access the column as shown below.
aspx:
VB:
Thanks,
Shinu.
The column index starts at index 2 beacuse GridExpandColumn and GridRowindicatorColumn are always in front of data columns.
If you are accessing using cell index then the "Name" column should have an index of 9. Otherwise you can set a UniqueName for the column and access the column as shown below.
aspx:
<
telerik:GridBoundColumn
DataField
=
"name"
UniqueName
=
"name"
HeaderText
=
"ISSUED TO"
/>
Private
Sub
RadGrid1_ItemDataBound(sender
As
Object
, e
As
GridItemEventArgs)
If
TypeOf
e.Item
Is
GridDataItem
Then
Dim
item
As
GridDataItem =
DirectCast
(e.Item, GridDataItem)
Dim
cell
As
TableCell = item(
"Name"
)
Dim
text
As
String
= cell.Text
End
If
End
Sub
Thanks,
Shinu.
0

Kevin
Top achievements
Rank 1
answered on 29 Mar 2012, 01:21 PM
Hi,
Ok got it, going to start using the uniques names to get at things, looks like a lot less toruble expecially if they change the amount of columns in the grid. thanks for the help.
Ok got it, going to start using the uniques names to get at things, looks like a lot less toruble expecially if they change the amount of columns in the grid. thanks for the help.