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

Radgrid client databinding

1 Answer 45 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Ron
Top achievements
Rank 1
Ron asked on 29 May 2012, 12:19 PM
Hi,

I have a grid template column that displays one of two images depending on the condition of the field e.g if true show on img if false show off img. Everything worked fine when I was using server side data binding but for unrelated reasons I had to switch to client side data binding and this feature no longer works. I'm getting the following error "Object cannot be cast from DBNull to other types." but there are no nulls in my data table at all. I'd really appreciate some help with this one. Here is the asp:
<telerik:GridTemplateColumn DataField="Active" UniqueName="Active">
                       <ItemStyle Width="20px" />
                       <ItemTemplate>
                       <div class="Tools" >
                            <asp:Image ID="ImgStatus" runat="server" ImageUrl='<%#Convert.ToBoolean(DataBinder.Eval(Container.DataItem, "Active"))? "~/Images/Icons/start.png" :
                            "~/Images/Icons/stop.png" %>'
                            AlternateText="Status"  ToolTip="Status" onclick="UpdateStatus();" /> 
                       </div>
                   </ItemTemplate>
               </telerik:GridTemplateColumn>
Thanks,
Ron.

1 Answer, 1 is accepted

Sort by
0
Richard
Top achievements
Rank 1
answered on 30 May 2012, 02:50 PM
Ron:

I do not believe that DataBinder.Eval(Container.DataItem, "Active") can be evaluated to a value when using client-side binding. See the response from Nikolay Rusev - Telerik Admin in this forum thread. He proposes an alternative way of binding the controls in the ItemTemplate.

In a server-bound template, you can use the <%# ... %> binding expression along with Eval() to render the value of a field from the data item. Equivalently, with a client-bound template, you can use the #= [field name] # expression to render the value of a data field. See this blog post for insights.

Also, you can reference the Grid/Client Binding online demo for further insights.

Hope this helps!
Tags
Grid
Asked by
Ron
Top achievements
Rank 1
Answers by
Richard
Top achievements
Rank 1
Share this question
or