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

[Solved] ItemDataBound problem

1 Answer 145 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Kjell
Top achievements
Rank 1
Iron
Iron
Kjell asked on 13 May 2013, 07:08 AM
I have a grid with a GridTemplateColumn and GridBoundColumn. If the GridBoundColumn "username" is empty (has no value), I want the GridTemplateColumn checkbox should be disabled.
<telerik:GridTemplateColumn DataField="cal_access" SortExpression="cal_access" UniqueName="cal_access" HeaderText="Ã…tkomst" HeaderButtonType="TextButton" HeaderStyle-Width="80px" AllowFiltering="False">
    <ItemTemplate>
         <asp:HiddenField ID="hfCalAccess" Value='<%# DataBinder.Eval(Container.DataItem, "id")%>' runat="server" />
         <asp:HiddenField ID="hfUsername" Value='<%# DataBinder.Eval(Container.DataItem, "username")%>' runat="server" />
         <asp:CheckBox ID="cbCalAccess" AutoPostBack="true" OnCheckedChanged="CalAccess_CheckedChanged" Checked='<%# DataBinder.Eval(Container.DataItem, "cal_access") %>' runat="server" />
    </ItemTemplate>
</telerik:GridTemplateColumn>

Protected 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 strxt As String = item("username").Text.ToString()
        If strxt = "myname" Then
            Dim chbx As CheckBox = DirectCast(item.FindControl("cbCalAccess"), CheckBox)
            chbx.Enabled = False
        End If
    End If
End Sub

If I enter "If strxt = 'myname' " so does the example above work fine, but not if I specify "If strxt = ''" (emty)". I want all rows where the column "username" has no value / is empty, checkbox being disabled and is not going to click in.
Why it works only if I specify a value, not if it has no value?


1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 13 May 2013, 09:10 AM
Hi,

Please try checking for '&nbsp;' instead of  ""  in the if condition. Please take a look into the following code snippet.

VB:
Protected 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 strxt As String = item("username").Text.ToString()
        If strxt = " " Then
            Dim chbx As CheckBox = DirectCast(item.FindControl("cbCalAccess"), CheckBox)
            chbx.Enabled = False
        End If
    End If
End Sub

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