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

How to change eval to Container.DataItem

2 Answers 915 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Reyaz
Top achievements
Rank 1
Reyaz asked on 16 Nov 2011, 08:06 AM
Hi,

How can I change DataBinder.Eval to Container.DataItem)["Value"] if grid is binding from data table.

<%#((System.Data.DataRowView)Container.DataItem)["Value"] %> is working fine in ItemTemplate but not in EditItemTemplate.


line of code which is not working.

 <EditItemTemplate>
<asp:TextBox ID="txtRestrictValue" runat="server" MaxLength="200" Text='<%#((System.Data.DataRowView)Container.DataItem)["Value"] %>'></asp:TextBox>
</EditItemTemplate>

it gives following error:
Unable to cast object of type 'Telerik.Web.UI.GridInsertionObject' to type 'System.Data.DataRowView'.

Warm Thnaks
Reyaz

2 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 16 Nov 2011, 09:03 AM
Hello,

Best  approach to set text property is by using Bind method, when RadGrid is in edit mode.

ASPX:
<asp:TextBox ID="txt" runat="server"  Text='<%# Bind("Value") %>'>
</asp:TextBox>

Thanks,
Princy.
0
Jayesh Goyani
Top achievements
Rank 2
answered on 16 Nov 2011, 09:52 AM
Hello,

you can also do this thing by below code snippet.

<asp:Label ID="Label1" runat="server" Text='<%# Eval("Name") %>'></asp:Label>


Thanks,
Jayesh Goyani
Tags
Grid
Asked by
Reyaz
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Jayesh Goyani
Top achievements
Rank 2
Share this question
or