I want to insert a new record into more than one MS access data table at one time.
Therefor I am using manual databinding in codebehind on the insert operation.
I've read and tried every solution i've found in this forum without any luck.
I'm using:
<
EditFormSettings EditFormType="Template">
I've tried retrieving the insert data both in ItemCommand and in InsertCommand:
| protected void detailsGrid_ItemCommand(object source, GridCommandEventArgs e) |
| { |
| if (e.CommandName == RadGrid.PerformInsertCommandName) |
| { |
| //GridEditableItem insertedItem = (GridEditableItem)e.Item; |
| GridEditFormInsertItem insertedItem = e.Item as GridEditFormInsertItem; |
| string LastName = (insertedItem["TextBox2"].Controls[0] as TextBox).Text; |
| } |
| } |
| protected void detailsGrid_InsertCommand(object source, GridCommandEventArgs e) |
| { |
| //GridEditableItem insertedItem = e.Item as GridEditableItem; |
| GridEditFormInsertItem insertedItem = e.Item as GridEditFormInsertItem; |
| string LastName = (insertedItem["TextBox2"].Controls[0] as TextBox).Text; |
| } |
Any suggestions are greatly appreciated
Regards
Janne P
9 Answers, 1 is accepted
| protected void detailsGrid_InsertCommand(object source, GridCommandEventArgs e) |
| { |
| GridEditFormInsertItem insertedItem = e.Item as GridEditFormInsertItem; |
| string LastName = (insertedItem.FindControl("TextBox2") as TextBox).Text; |
| } |
However insertedItem still returns Null thus giving me the ugly "NullReferenceException" reply.
Do you or anybody have any other ideas?
Here's more details:
| <telerik:RadGrid ID="detailsGrid" |
| runat="server" |
| DataSourceID="ds_detailsGrid" |
| GridLines="None" |
| Width="512px" |
| ShowHeader="False" |
| Skin="" |
| EnableEmbeddedSkins="False" |
| AutoGenerateColumns="False" |
| AllowAutomaticUpdates="True" |
| AllowAutomaticInserts="False" |
| AllowAutomaticDeletes="True" |
| OnItemUpdated="detailsGrid_ItemUpdated" |
| OnItemInserted="detailsGrid_ItemInserted" |
| OnItemCommand="detailsGrid_ItemCommand" |
| OnDataBound="detailsGrid_OnDataBound" |
| OnPreRender="detailsGrid_PreRender" |
| OnInsertCommand="detailsGrid_InsertCommand" > //// <
MasterTableView CommandItemDisplay="Top" DataKeyNames="bokareId"
DataSourceID="ds_detailsGrid">
<
EditFormSettings EditFormType="Template">
<EditColumn Visible="false">
</EditColumn>
<FormTemplate>
</FormTemplate>
</EditFormSettings>
|
Thanks
//janne
I've found out that it works when I use the default "Save New" but
it doesn't work when I use <CommandItemTemplate> buttons.
The reason that I need to use <CommandItemTemplate> is that I
want to use templates in the edit form.
Does this information give anybody any ideas?
Thanks
Janne P
| <EditFormSettings EditFormType="Template"> |
| <FormTemplate> |
| // Edit Form content |
| <asp:Button ID="Button1" runat="server" CommandName="PerformInsert" Text="Save" /> |
| </FormTemplate> |
| </EditFormSettings> |
This did the trick :-)
So if I understand correct it's not possible to trigger the InsertCommand from inside
CommandItemTemplate?
Seems a little weird to me if so because for instance the UpdateEditedCommand is
triggered from inside the CommandItemTemplate.
Thanks again.
Janne
Certainly you can trigger the Insert command from the CommandItemTemplate of the grid, you just have to make sure that the button you have placed into it, has its CommandName property set to PerformInsert, as Shinu has rightly pointed out.
Regards,
Tsvetoslav
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.
Thank you for your reply. However I've done more tests and I don't manage
to get it to work from inside CommandItemTemplate. Maybe there's something else I'm missing.
My code:
| <MasterTableView CommandItemDisplay="Top" DataKeyNames="bokareId" DataSourceID="ds_detailsGrid"> |
| <Columns> |
| <telerik:GridTemplateColumn UniqueName="TemplateColumn"> |
| <ItemTemplate> |
| //itemtemplatecontent |
| </ItemTemplate> |
| </telerik:GridTemplateColumn> |
| </Columns> |
| <EditFormSettings EditFormType="Template"> |
| <FormTemplate> |
| <asp:TextBox ID="Enamn" runat="server" Text='<%# Bind("fldEnamn") %>'></asp:TextBox> |
| <asp:LinkButton ID="btnSaveNew1" runat="server" CommandName="PerformInsert"> |
| SaveNew1 |
| </asp:LinkButton> |
| </FormTemplate> |
| </EditFormSettings> |
| <CommandItemTemplate> |
| <asp:LinkButton ID="btnSaveNew2" runat="server" CommandName="PerformInsert"> |
| SaveNew2 |
| </asp:LinkButton> |
| </CommandItemTemplate> |
| protected void detailsGrid_InsertCommand(object source, GridCommandEventArgs e) |
| { |
| //Get the GridEditFormInsertItem of the RadGrid |
| GridEditFormInsertItem insertedItem = e.Item as GridEditFormInsertItem; |
| string LastName = (insertedItem.FindControl("Enamn") as TextBox).Text; |
| } |
btnSaveNew1 is working but btnSaveNew2 inside <CommandItemTemplate is giving me
the "System.NullReferenceException was unhandled by user code" error.
Feels like there's something else wrong with my code..... Do you find it?
Thanks again!
Regards
Janne P
| protected void detailsGrid_InsertCommand(object source, GridCommandEventArgs e) |
| { |
| GridEditFormInsertItem insertItem = (GridEditFormInsertItem)RadGrid1.MasterTableView.GetInsertItem(); |
| } |
This did it for me :-) Thank you!!!
I do set the grid in Insert Mode by using another button as you describe.
But what did the trick was your snippet:
GridEditFormInsertItem
insertItem = (GridEditFormInsertItem)detailsGrid.MasterTableView.GetInsertItem();
I haven't come across this code before anywhere else.
Thanks again for your time and effort!
Best regards
Janne