If there are items in the table feeding the grid the grid will display the items.
If there are no items in the table I want to display the grid with the edit form showing, just as if the user had clicked "Add new item". Edit Mode is InPlace but I am using ItemTemplate and EditItemTemplate to present the data on a form.
I could manually add a new item to the table and then use grd.EditIndexes.Add(0) to force the grid to edit the item. This would leave a blank item in the table if the user clicked cancel that I would then have to code for.
There must be a simple way of forcing the grid into "Add new" and hence edit mode.
Declan
If there are no items in the table I want to display the grid with the edit form showing, just as if the user had clicked "Add new item". Edit Mode is InPlace but I am using ItemTemplate and EditItemTemplate to present the data on a form.
I could manually add a new item to the table and then use grd.EditIndexes.Add(0) to force the grid to edit the item. This would leave a blank item in the table if the user clicked cancel that I would then have to code for.
There must be a simple way of forcing the grid into "Add new" and hence edit mode.
Declan
11 Answers, 1 is accepted
0
Hello Declan ,
You can set MasterTableView.IsItemInserted to true to have permanent insert item.
Sincerely yours,
Vlad
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center
You can set MasterTableView.IsItemInserted to true to have permanent insert item.
Sincerely yours,
Vlad
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center
0

Declan
Top achievements
Rank 2
answered on 15 Jul 2008, 03:19 PM
Hi Vlad,
That was a fast response :)
One minor problem - I have a check box on the form and was using
Private Sub grdUpdate_ItemCommand(ByVal source As Object, ByVal e As Telerik.WebControls.GridCommandEventArgs) Handles grdUpdate.ItemCommand
If e.CommandName = RadGrid.InitInsertCommandName Then
' Set default values for check boxes
e.Canceled = True
Dim newValues As New System.Collections.Specialized.ListDictionary()
newValues("DeliveryAsBefore") = False
'Insert the item and rebind
e.Item.OwnerTableView.InsertItem(newValues)
End If
End Sub
to set a default value of Unchecked.
Using grdUpdate.MasterTableView.IsItemInserted = True results in an error converting DBNull to Boolean.
If I remove the check box the error disappears. Any suggestion?
Declan
That was a fast response :)
One minor problem - I have a check box on the form and was using
Private Sub grdUpdate_ItemCommand(ByVal source As Object, ByVal e As Telerik.WebControls.GridCommandEventArgs) Handles grdUpdate.ItemCommand
If e.CommandName = RadGrid.InitInsertCommandName Then
' Set default values for check boxes
e.Canceled = True
Dim newValues As New System.Collections.Specialized.ListDictionary()
newValues("DeliveryAsBefore") = False
'Insert the item and rebind
e.Item.OwnerTableView.InsertItem(newValues)
End If
End Sub
to set a default value of Unchecked.
Using grdUpdate.MasterTableView.IsItemInserted = True results in an error converting DBNull to Boolean.
If I remove the check box the error disappears. Any suggestion?
Declan
0
Hi Declan ,
Please remove the Bind() expression if you have such declared.
Kind regards,
Vlad
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center
Please remove the Bind() expression if you have such declared.
Kind regards,
Vlad
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center
0

Declan
Top achievements
Rank 2
answered on 15 Jul 2008, 03:29 PM
Hi Vlad,
Yes I had a Bind in the edit form and removing it removes the error. How then do I display the original value if the user clicks edit? The checkbox would not be bound to the column in the table on edit.
Declan
Yes I had a Bind in the edit form and removing it removes the error. How then do I display the original value if the user clicks edit? The checkbox would not be bound to the column in the table on edit.
Declan
0
Hello Declan ,
How to set predefined values for different column editors on init insert you can learn from the following documentation topics:
http://www.telerik.com/help/aspnet-ajax/grdinsertingvaluesinplaceandeditforms.html (the last paragraph)
http://www.telerik.com/help/aspnet-ajax/grderrormessages.html (paragraph 2)
Best regards,
Stephen
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center
How to set predefined values for different column editors on init insert you can learn from the following documentation topics:
http://www.telerik.com/help/aspnet-ajax/grdinsertingvaluesinplaceandeditforms.html (the last paragraph)
http://www.telerik.com/help/aspnet-ajax/grderrormessages.html (paragraph 2)
Best regards,
Stephen
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center
0

Declan
Top achievements
Rank 2
answered on 15 Jul 2008, 04:20 PM
Hi Stephen,
Sorry but I am confused :(
It was from these articles that I discovered how to set the default values on insert.
My problem is - how do I show the table field original value in the edit form when the user clicks Edit. A Bind("CheckBoxField") will display the value in normal display mode and the sample code will display a new default value on Add New.
Before I tried to go into EditMode when there were no items in the table I had a Bind() in my edit form and all worked just fine. Now that I added
If coll.Count < 1 Then
grdUpdate.MasterTableView.IsItemInserted = True
End If
to the NeedDataSource event I get an error. Removing the Bind() resolves the error but the original field value is not displayed.
Regards,
Declan
Private Sub grdUpdate_ItemCommand(ByVal source As Object, ByVal e As Telerik.WebControls.GridCommandEventArgs) Handles grdUpdate.ItemCommand
If e.CommandName = RadGrid.InitInsertCommandName Then
' Set default values for check boxes on insert
' cancel the default operation
e.Canceled = True
Dim newValues As New System.Collections.Specialized.ListDictionary()
newValues("DeliveryAsBefore") = False
'Insert the item and rebind
e.Item.OwnerTableView.InsertItem(newValues)
If for example the table column value is true (checked) how do I display this in the edit form?
<asp:CheckBox id="CheckBox1" runat="server"
Text="Delivery as before"
Enabled="false"
AutoPostBack="False"
Checked='<%# Bind("DeliveryAsBefore") %>'
Visible="true" >
</asp:CheckBox>
</ItemTemplate>
<EditItemTemplate>
<asp:CheckBox id="chkDeliveryAsBefore" runat="server"
Text="Tick here if you require Delivery as before"
Enabled="true"
AutoPostBack="False"
Visible="true" >
</asp:CheckBox>
</EditItemTemplate>
Sorry but I am confused :(
It was from these articles that I discovered how to set the default values on insert.
My problem is - how do I show the table field original value in the edit form when the user clicks Edit. A Bind("CheckBoxField") will display the value in normal display mode and the sample code will display a new default value on Add New.
Before I tried to go into EditMode when there were no items in the table I had a Bind() in my edit form and all worked just fine. Now that I added
If coll.Count < 1 Then
grdUpdate.MasterTableView.IsItemInserted = True
End If
to the NeedDataSource event I get an error. Removing the Bind() resolves the error but the original field value is not displayed.
Regards,
Declan
Private Sub grdUpdate_ItemCommand(ByVal source As Object, ByVal e As Telerik.WebControls.GridCommandEventArgs) Handles grdUpdate.ItemCommand
If e.CommandName = RadGrid.InitInsertCommandName Then
' Set default values for check boxes on insert
' cancel the default operation
e.Canceled = True
Dim newValues As New System.Collections.Specialized.ListDictionary()
newValues("DeliveryAsBefore") = False
'Insert the item and rebind
e.Item.OwnerTableView.InsertItem(newValues)
If for example the table column value is true (checked) how do I display this in the edit form?
<asp:CheckBox id="CheckBox1" runat="server"
Text="Delivery as before"
Enabled="false"
AutoPostBack="False"
Checked='<%# Bind("DeliveryAsBefore") %>'
Visible="true" >
</asp:CheckBox>
</ItemTemplate>
<EditItemTemplate>
<asp:CheckBox id="chkDeliveryAsBefore" runat="server"
Text="Tick here if you require Delivery as before"
Enabled="true"
AutoPostBack="False"
Visible="true" >
</asp:CheckBox>
</EditItemTemplate>
0
Hi Declan ,
As you can see from the linked resources, the Checked property of the checkbox residing inside the EditItemTemplate is set using Bind("fieldName") expression and the predefined value is set intercepting the ItemCommand event (when e.CommandName is InitInsert). This should work properly both for edit and insert mode and the state of the checkbox should be set accordingly.
Let me know if I am leaving something out.
Best regards,
Stephen
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center
As you can see from the linked resources, the Checked property of the checkbox residing inside the EditItemTemplate is set using Bind("fieldName") expression and the predefined value is set intercepting the ItemCommand event (when e.CommandName is InitInsert). This should work properly both for edit and insert mode and the state of the checkbox should be set accordingly.
Let me know if I am leaving something out.
Best regards,
Stephen
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center
0

Declan
Top achievements
Rank 2
answered on 17 Jul 2008, 02:47 PM
Hi Stephen,
I seem to have narrowed it down. The event :
Protected Sub grdUpdate_ItemCommand(ByVal source As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles grdUpdate.ItemCommand
is not getting fired!
Any thoughts?
regards,
Declan
I seem to have narrowed it down. The event :
Protected Sub grdUpdate_ItemCommand(ByVal source As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles grdUpdate.ItemCommand
is not getting fired!
Any thoughts?
regards,
Declan
0
Hello Declan,
Does adding Handles clause at the end of the event handler fixes the issue, i.e.:
Handles RadGrid.ItemCommand
Also verify that the viewstate for the grid is enabled.
Best regards,
Stephen
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center
Does adding Handles clause at the end of the event handler fixes the issue, i.e.:
Handles RadGrid.ItemCommand
Also verify that the viewstate for the grid is enabled.
Best regards,
Stephen
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center
0

Declan
Top achievements
Rank 2
answered on 21 Jul 2008, 04:57 PM
I give up :(
Either You don't understand the problem or I don't understand the answer but I just cannot get what I want to work.
Instead I have a workaround that adds a row to my table, if the table is empty, setting checkbox default values before displaying the grid to the user. As there is only one row in the grid I add EditIndexes ( grd.EditIndexes.Add(0)) and this achieves my requirement.
If the user decides to cancel I just delete the row just added.
Either You don't understand the problem or I don't understand the answer but I just cannot get what I want to work.
Instead I have a workaround that adds a row to my table, if the table is empty, setting checkbox default values before displaying the grid to the user. As there is only one row in the grid I add EditIndexes ( grd.EditIndexes.Add(0)) and this achieves my requirement.
If the user decides to cancel I just delete the row just added.
0
Hi Declan ,
If you send us small example via support ticket demonstrating the problem we will gladly help you.
Greetings,
Vlad
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center
If you send us small example via support ticket demonstrating the problem we will gladly help you.
Greetings,
Vlad
the Telerik team
Instantly find answers to your questions at the new Telerik Support Center