Robert Jakech
Top achievements
Rank 1
Robert Jakech
asked on 12 Mar 2010, 06:04 PM
Hi,
I have a radgrid from which i insert/edit records via Editform/Usercontrol.
Now, each time i enter records and click insert, the form/usercontrol disappears.
What i want to do/achieve is make the editform/usercontrol stay when i click 'Insert' button, so that i keep entering/inserting new records until i am done. Then i can click 'EXIT' to close the editform.
How can i achieve this? Do i need a javascript script to do that? if so, can someone please post me a script or point me to a demo using Radgrid?
thanks
Robert.
3 Answers, 1 is accepted
0
Princy
Top achievements
Rank 2
answered on 15 Mar 2010, 08:36 AM
Hi,
Try the code snippt below and let me know how it goes.
C#
Thanks,
Princy
Try the code snippt below and let me know how it goes.
C#
| |
| protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e) |
| { |
| //to keep the insert form open after insert |
| if (e.CommandName == RadGrid.PerformInsertCommandName) |
| { |
| // after inserting into database |
| e.Canceled = true; |
| } |
| // to close the insert form on exit |
| if (e.CommandName == "exit") |
| { |
| // after updating the database |
| RadGrid1.MasterTableView.IsItemInserted =false; |
| RadGrid1.Rebind(); |
| } |
| } |
Thanks,
Princy
0
Robert Jakech
Top achievements
Rank 1
answered on 16 Mar 2010, 10:43 AM
It worked perfectly.
Thanks alot.
0
Robert Jakech
Top achievements
Rank 1
answered on 18 Mar 2010, 01:45 PM
Hi, in line with editing in RADGRID.
Thank you very much for the piece of code. It works very well on single grids.
In a scenario where I have hierachical grids i.e Master/Child(i can click to expand)
it seems not applicable.
Am i missing something? Check below my .aspx code:
<MasterTableView AllowMultiColumnSorting="True" DataKeyNames="Id" DataSourceID="Category"
CommandItemDisplay="Top" Name="Category">
<DetailTables>
<rad:GridTableView runat="server" CommandItemDisplay="Top" DataKeyNames="Id" DataSourceID="Sponsors"
Name="Sponsors" AllowMultiColumnSorting="True" AllowAutomaticDeletes="false"
AllowAutomaticInserts="false" AllowAutomaticUpdates="false">
<ParentTableRelation>
<rad:GridRelationFields DetailKeyField="CategoryID" MasterKeyField="Id" />
</ParentTableRelation>
<RowIndicatorColumn>
<HeaderStyle Width="20px" />
</RowIndicatorColumn>
<ExpandCollapseColumn>
<HeaderStyle Width="20px" />
</ExpandCollapseColumn>
<Columns>
<rad:GridEditCommandColumn ButtonType="ImageButton" EditImageUrl="~/Resources/Buttons/EditButton.jpg">
</rad:GridEditCommandColumn>
<rad:GridBoundColumn DataField="ID" HeaderButtonType="TextButton" HeaderText="Sponsor ID"
SortExpression="ID" UniqueName="SponsorID">
</rad:GridBoundColumn>
<rad:GridBoundColumn DataField="SponsorName" HeaderButtonType="TextButton" HeaderText="Sponsor Name"
UniqueName="Sponsor Name">
</rad:GridBoundColumn>
<rad:GridBoundColumn DataField="Telephone" HeaderButtonType="TextButton" HeaderText="Telephone"
UniqueName="Telephone">
</rad:GridBoundColumn>
<rad:GridBoundColumn DataField="Address" HeaderButtonType="TextButton" HeaderText="Address"
UniqueName="Address">
</rad:GridBoundColumn>
<rad:GridBoundColumn DataField="Email" HeaderButtonType="TextButton" HeaderText="Email"
UniqueName="Email">
</rad:GridBoundColumn>
<rad:GridBoundColumn DataField="CategoryID" HeaderButtonType="TextButton" HeaderText="Category"
UniqueName="CategoryID" Visible="false">
</rad:GridBoundColumn>
<rad:GridButtonColumn ButtonType="ImageButton" CommandName="Delete" ImageUrl="~/Resources/Buttons/DeleteButton.jpg"
Text="Delete" UniqueName="BtnDel">
</rad:GridButtonColumn>
</Columns>
<EditFormSettings EditFormType="Template">
<FormTemplate>
<table>
<tr>
<td>
<asp:Label ID="Label1" runat="server">Sponsor Name:</asp:Label>
</td>
<td>
<asp:TextBox ID="SponsorTextBox" Text='<%# Eval("SponsorName") %>' Width="155px"
runat="server">
</asp:TextBox>
<asp:RequiredFieldValidator id="ReqSponsorTextBox" runat="server" ErrorMessage="<br>* Required" ControlToValidate="SponsorTextBox"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td>
<asp:Label ID="Label2" runat="server">Telephone:</asp:Label>
</td>
<td>
<asp:TextBox ID="TelTextBox" Width="155px" runat="server" Text='<%# Eval("Telephone") %>'>
</asp:TextBox>
<%--<asp:RequiredFieldValidator id="ReqTelTextBox" runat="server" ErrorMessage="<br>* Required" ControlToValidate="TelTextBox"></asp:RequiredFieldValidator>--%>
</td>
</tr>
<tr>
<td>
<asp:Label ID="Label3" runat="server">Address:</asp:Label>
</td>
<td>
<asp:TextBox ID="AddressTextBox" Text='<%# Eval("Address") %>' runat="server" Height="75px"
Width="155px" TextMode="MultiLine">
</asp:TextBox>
<asp:RequiredFieldValidator id="ReqAddressTextBox" runat="server" ErrorMessage="<br>* Required" ControlToValidate="AddressTextBox"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td>
<asp:Label ID="Label4" runat="server">Email:</asp:Label>
</td>
<td>
<asp:TextBox ID="EmailTextBox" Text='<%# Eval("Email") %>' Width="155px" runat="server"
EmptyMessage="you@domain.com" EmptyMessageStyle-ForeColor="GrayText">
</asp:TextBox>
</td>
</tr>
<tr>
<td>
<asp:ImageButton ID="LinkInsert" Text='<%# (Container is GridEditFormInsertItem) ? "Insert" : "Update" %>'
ImageUrl="~/Resources/Buttons/SaveButton.jpg" runat="server" CommandName='<%# (Container is GridEditFormInsertItem) ? "PerformInsert" : "Update" %>'
Visible='<%# (Container is GridEditFormInsertItem) ? true : false %>' />
<asp:ImageButton ID="LinkButton1" Text='<%# (Container is GridEditFormInsertItem) ? "Insert" : "Update" %>'
ImageUrl="~/Resources/Buttons/SaveButton.jpg" runat="server" CommandName='<%# (Container is GridEditFormInsertItem) ? "PerformInsert" : "Update" %>'
Visible='<%# (Container is GridEditFormInsertItem) ? false : true %>' />
<asp:ImageButton ID="LinkButtonCancel" ImageUrl="~/Resources/Buttons/CancelButton.jpg"
runat="server" Text="Cancel" CausesValidation="false" CommandName="Cancel" />
</td>
</tr>
<td>
<tr>
<td>
<asp:TextBox ID="IDTextBox" Text='<%# Eval("Id") %>' runat="server" Visible="false">
</asp:TextBox>
</td>
</tr>
</table>
</FormTemplate>
<EditColumn UniqueName="EditCommandColumn1">
</EditColumn>
</EditFormSettings>
</rad:GridTableView>
</DetailTables>
<RowIndicatorColumn>
<HeaderStyle Width="20px"></HeaderStyle>
</RowIndicatorColumn>
<ExpandCollapseColumn Visible="True">
<HeaderStyle Width="20px"></HeaderStyle>
</ExpandCollapseColumn>
<Columns>
<rad:GridEditCommandColumn ButtonType="ImageButton" EditImageUrl="~/Resources/Buttons/EditButton.jpg">
</rad:GridEditCommandColumn>
<rad:GridBoundColumn DataField="Id" HeaderText="Category ID" SortExpression="Id"
UniqueName="Id">
</rad:GridBoundColumn>
<rad:GridBoundColumn DataField="SponsorCategory" HeaderText="Category Name" SortExpression="SponsorCategory" ConvertEmptyStringToNull="false"
UniqueName="SponsorCategory">
</rad:GridBoundColumn>
<rad:GridButtonColumn ButtonType="ImageButton" CommandName="Delete" ImageUrl="~/Resources/Buttons/DeleteButton.jpg"
Text="Delete" UniqueName="column">
</rad:GridButtonColumn>
</Columns>
<EditFormSettings EditFormType="Template">
<FormTemplate>
<table>
<tr>
<td>
<asp:Label ID="lblCategory" runat="server">Sponsor Category:</asp:Label>
</td>
<td>
<asp:TextBox ID="CategoryTextBox" runat="server" Text='<%# Eval("SponsorCategory") %>'>
</asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="<br>* Required"
ControlToValidate="CategoryTextBox"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td>
<asp:Label ID="lblID" runat="server" Visible="false">Sponsor ID:</asp:Label>
</td>
<td>
<asp:TextBox ID="IDTextBox" runat="server" Visible="false" Text='<%# Eval("Id") %>'>
</asp:TextBox>
</td>
</tr>
<tr>
<td>
<asp:ImageButton ID="LinkInsert" Text='<%# (Container is GridEditFormInsertItem) ? "Insert" : "Update" %>'
ImageUrl="~/Resources/Buttons/SaveButton.jpg" runat="server" CommandName='<%# (Container is GridEditFormInsertItem) ? "PerformInsert" : "Update" %>'
Visible='<%# (Container is GridEditFormInsertItem) ? true : false %>' />
<asp:ImageButton ID="LinkUpdate" Text='<%# (Container is GridEditFormInsertItem) ? "Insert" : "Update" %>'
ImageUrl="~/Resources/Buttons/SaveButton.jpg" runat="server" CommandName='<%# (Container is GridEditFormInsertItem) ? "PerformInsert" : "Update" %>'
Visible='<%# (Container is GridEditFormInsertItem) ? false : true %>' />
<asp:ImageButton ID="LinkButtonCancel" runat="server" Text="Cancel" CausesValidation="false"
ImageUrl="~/Resources/Buttons/CancelButton.jpg" CommandName="Cancel" />
</td>
<%--<td>
<asp:ImageButton ID="LinkInsert" Text='<%# (Container is GridEditFormInsertItem) ? "Insert" : "Update" %>'
ImageUrl="~/Resources/Buttons/SaveButton.jpg" runat="server" CommandName='<%# (Container is GridEditFormInsertItem) ? "PerformInsert" : "Update" %>'
OnClick="CountryInsert" Visible='<%# (Container is GridEditFormInsertItem) ? true : false %>' />
<asp:ImageButton ID="LinkUpdate" Text='<%# (Container is GridEditFormInsertItem) ? "Insert" : "Update" %>'
ImageUrl="~/Resources/Buttons/SaveButton.jpg" runat="server" CommandName='<%# (Container is GridEditFormInsertItem) ? "PerformInsert" : "Update" %>'
OnClick="CountryUpdate" Visible='<%# (Container is GridEditFormInsertItem) ? false : true %>' />
<asp:ImageButton ID="LinkButtonCancel" runat="server" Text="Cancel" CausesValidation="false"
ImageUrl="~/Resources/Buttons/CancelButton.jpg" CommandName="Cancel" />
</td>--%>
</tr>
</table>
</FormTemplate>
<EditColumn UniqueName="EditSponsorsCategory">
</EditColumn>
</EditFormSettings>
</MasterTableView>
NOTE: I am using 'your code' within ONITEMINSERTED.(It would not work) on ITEMCOMMAND.
Thanks.
I need your help.