Hi
I am using this demo for my example.
http://demos.telerik.com/aspnet-ajax/grid/examples/dataediting/popupeditform/defaultcs.aspx
For the pop up form, I only want to display a checkbox when editing, not inserting. However I can not seem to get it working.
Have tried:
| <tr ID="tr1" runat="server" visible='<%# !(Container is GridEditFormInsertItem) %>'> |
| <td>Archived:</td> |
| <td><asp:CheckBox ID="Archived" runat="server" Checked='<%# Bind("Archived") %>' Text="Don't display." /></td> |
| </tr> |
However there is no Bind in inserting. It work in Updating but on inserting I get a cast error.
I also tried this:
| <% if (!(Container is GridEditFormInsertItem)) { %> |
| <tr> |
| <td>Archived:</td> |
| <td><asp:CheckBox ID="Archived" runat="server" Checked='<%# Bind("Archived") %>' Text="Don't display." /></td> |
| </tr> |
| <%} %> |
And yep couldn't get this working too. Can anyone help? Thanks.
5 Answers, 1 is accepted
0
Princy
Top achievements
Rank 2
answered on 13 Jul 2009, 07:12 AM
Hello Michael,
You can hide the checkbox in the InsertMode using the following code:
aspx:
Thanks
Princy.
You can hide the checkbox in the InsertMode using the following code:
aspx:
| <table> |
| <tr id="tr1" runat="server" visible='<%#(Container is GridEditFormInsertItem)? false : true %>'> |
| <td> |
| Archived:</td> |
| <td> |
| <asp:CheckBox ID="Archived" runat="server" Checked='<%#Bind("Archived")%>' Text="Don't display." /></td> |
| </tr> |
| </table> |
Thanks
Princy.
0
Michael
Top achievements
Rank 1
answered on 14 Jul 2009, 06:38 AM
nop still doesn't work :( (Your first line did work though, so thanks for that.)
The error is in the CheckBox Checked Bind, even when it's invisible it still gives me an error. Even worse, when it works in update mode, when I press the update button, it is NOT updated in the database. If I manually set the Archived bit as 1 in the database, then yes the Archived check box on an update is checked, so that binds, however when I go to Update the record, even if its checked, it goes to false! So the database Archived bit goes back to 0, even if the CheckBox was checked.
I tried to overwrite archived in the UpdateAddressBook method with true, and it worked, so the functions work, but there is something going in the objectdatasource :(
The error when running the page and pressing the add record button occurs on the asp:CheckBox line
System.InvalidCastException: Specified cast is not valid
As I said the TextBox and DropDownList controls to update the other records ALL work fine in insert and update, it's just the archived checkbox that is playing up. Grrrrr
The error is in the CheckBox Checked Bind, even when it's invisible it still gives me an error. Even worse, when it works in update mode, when I press the update button, it is NOT updated in the database. If I manually set the Archived bit as 1 in the database, then yes the Archived check box on an update is checked, so that binds, however when I go to Update the record, even if its checked, it goes to false! So the database Archived bit goes back to 0, even if the CheckBox was checked.
I tried to overwrite archived in the UpdateAddressBook method with true, and it worked, so the functions work, but there is something going in the objectdatasource :(
| <tr id="tr1" runat="server" visible='<%#(Container is GridEditFormInsertItem)? false : true %>'> |
| <td>Archived:</td> |
| <td><asp:CheckBox ID="Archived" runat="server" Checked='<%# Bind("Archived") %>' Text="Don't display." /></td> |
| </tr> |
The error when running the page and pressing the add record button occurs on the asp:CheckBox line
System.InvalidCastException: Specified cast is not valid
| <asp:ObjectDataSource ID="AddressBook_objAddressBookDataSource" EnablePaging="true" SelectMethod="GetAddressBook" SelectCountMethod="GetAddressBookCount" InsertMethod="InsertAddressBook" UpdateMethod="UpdateAddressBook" DeleteMethod="DeleteAddressBook" runat="server" TypeName="MMM.EWAREV2.BLL.Accounts.AddressBook"> |
| <SelectParameters> |
| <asp:SessionParameter Name="companyId" SessionField="CompanyId" Type="Int32" /> |
| </SelectParameters> |
| <InsertParameters> |
| <asp:SessionParameter Name="companyId" SessionField="CompanyId" Type="Int32" /> |
| <asp:Parameter Name="companyName" Type="String" /> |
| <asp:Parameter Name="attentionTo" Type="String" /> |
| <asp:Parameter Name="addressLine1" Type="String" /> |
| <asp:Parameter Name="addressLine2" Type="String" /> |
| <asp:Parameter Name="addressLine3" Type="String" /> |
| <asp:Parameter Name="suburb" Type="String" /> |
| <asp:Parameter Name="state" Type="String" /> |
| <asp:Parameter Name="postcode" Type="String" /> |
| <asp:Parameter Name="country" Type="String" /> |
| <asp:ProfileParameter Name="createdBy" PropertyName="UserName" Type="String" /> |
| <asp:Parameter Name="archived" DefaultValue="false" Type="Boolean" /> |
| </InsertParameters> |
| <UpdateParameters> |
| <asp:Parameter Name="companyName" Type="String" /> |
| <asp:Parameter Name="attentionTo" Type="String" /> |
| <asp:Parameter Name="addressLine1" Type="String" /> |
| <asp:Parameter Name="addressLine2" Type="String" /> |
| <asp:Parameter Name="addressLine3" Type="String" /> |
| <asp:Parameter Name="suburb" Type="String" /> |
| <asp:Parameter Name="state" Type="String" /> |
| <asp:Parameter Name="postcode" Type="String" /> |
| <asp:Parameter Name="country" Type="String" /> |
| <asp:Parameter Name="archived" DefaultValue="false" Type="Boolean" /> |
| </UpdateParameters> |
| </asp:ObjectDataSource> |
0
Princy
Top achievements
Rank 2
answered on 14 Jul 2009, 07:50 AM
Hi Michael,
This error is found to occur when your grid instance cannot bind a value for the newly inserted item through the Eval()/Bind() syntax you have hard-coded. To avoid this error you can preset the value of the checkbox when binding to a grid item on the InitInsertCommand as shown below:
c#:
Hope this helps...
Princy.
This error is found to occur when your grid instance cannot bind a value for the newly inserted item through the Eval()/Bind() syntax you have hard-coded. To avoid this error you can preset the value of the checkbox when binding to a grid item on the InitInsertCommand as shown below:
c#:
| protected void RadGrid1_ItemCommand(object source, Telerik.Web.UI.GridCommandEventArgs e) |
| { |
| if ((e.CommandName == RadGrid.InitInsertCommandName)) |
| { |
| e.Canceled = true; |
| //Prepare an IDictionary with the predefined values |
| System.Collections.Specialized.ListDictionary newValues = new System.Collections.Specialized.ListDictionary(); |
| //set initial checked state for the checkbox on init insert |
| newValues("Archived") = false; |
| //Insert the item and rebind |
| e.Item.OwnerTableView.InsertItem(newValues); |
| } |
| } |
Hope this helps...
Princy.
0
Michael
Top achievements
Rank 1
answered on 14 Jul 2009, 11:41 AM
Thanks Princy
This has helped a lot for the insert, it now works. Thanks heaps.
However the update command still doesn't work :(
No errors are been thrown. However the Archived value been passed into the UpdateMethod="UpdateAddressBook" is always false, no matter what I do. All the other values do get updated correctly.
Do you have an idea why the CheckBox is always passing false into the UpdateAddressBook method?
This has helped a lot for the insert, it now works. Thanks heaps.
However the update command still doesn't work :(
No errors are been thrown. However the Archived value been passed into the UpdateMethod="UpdateAddressBook" is always false, no matter what I do. All the other values do get updated correctly.
Do you have an idea why the CheckBox is always passing false into the UpdateAddressBook method?
0
Hello Michael,
Since you do not have binding expression for the checkbox in the insertion form, you will need to pass the value from that checkbox manually to your UpdateAddressBook method (as opposed to when having two-way binding with Bind(field) expression).
How to extract the new values from the RadGrid edit/insert form you can see from the online demos below:
http://demos.telerik.com/aspnet-ajax/grid/examples/dataediting/extractvalues/defaultcs.aspx
http://demos.telerik.com/aspnet-ajax/grid/examples/dataediting/editmodes/defaultcs.aspx
Kind regards,
Sebastian
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Since you do not have binding expression for the checkbox in the insertion form, you will need to pass the value from that checkbox manually to your UpdateAddressBook method (as opposed to when having two-way binding with Bind(field) expression).
How to extract the new values from the RadGrid edit/insert form you can see from the online demos below:
http://demos.telerik.com/aspnet-ajax/grid/examples/dataediting/extractvalues/defaultcs.aspx
http://demos.telerik.com/aspnet-ajax/grid/examples/dataediting/editmodes/defaultcs.aspx
Kind regards,
Sebastian
the Telerik team
Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.