| protected void RadGrid1_InsertCommand(object source, GridCommandEventArgs e) |
| { |
| GridEditableItem item = e.Item as GridEditableItem; |
| string type = (item.FindControl("priorityComboBox") as RadComboBox).SelectedValue.ToString(); |
| string Message = (item.FindControl("TextBox1") as TextBox).Text; |
| string todo_date = (item.EditManager.GetColumnEditor("Todo_date") as GridDateTimeColumnEditor).Text; |
| string InsertSQL = "INSERT INTO [ToDo] ([Message], [Todo_Date], [Type],[AdminID]) VALUES ('"+Message+"','"+todo_date+"','"+type+"',1)" ; |
| String ConnString = ConfigurationManager.ConnectionStrings["SchedulerConnectionString"].ConnectionString; |
| SqlConnection conn = new SqlConnection(ConnString); |
| SqlCommand cmd = new SqlCommand(InsertSQL, conn); |
| int flag; |
| try |
| { |
| conn.Open(); |
| flag = cmd.ExecuteNonQuery(); |
| } |
| finally |
| { |
| conn.Close(); |
| } |
| } |
| <telerik:RadGrid runat="server" ID="RadGrid1" GridLines="None" |
| AutoGenerateColumns="False" Skin="Office2007" style="border: none;" height="100%" |
| AllowAutomaticInserts="True" AllowAutomaticUpdates="true" ShowFooter="true" |
| AllowSorting="true" onitemupdated="RadGrid1_ItemUpdated" |
| onneeddatasource="RadGrid1_NeedDataSource" |
| ondetailtabledatabind="RadGrid1_DetailTableDataBind" |
| oninsertcommand="RadGrid1_InsertCommand" |
| oniteminserted="RadGrid1_ItemInserted"> |
| <ClientSettings AllowExpandCollapse="true"> |
| <ClientEvents OnRowDblClick="RowDblClicked" /> |
| </ClientSettings> |
| <%--<ClientSettings AllowRowsDragDrop="false" AllowExpandCollapse="true"> |
| <Selecting AllowRowSelect="True" /> |
| <ClientEvents OnRowDblClick="RowDblClicked" /> |
| </ClientSettings>--%> |
| <MasterTableView runat="server" DataKeyNames="Todo_Date" InsertItemDisplay="Bottom" EditMode="InPlace" AllowMultiColumnSorting="true" Width="100%" HierarchyLoadMode="Client" CommandItemDisplay="Top" AllowAutomaticInserts="true" > |
| <SortExpressions> |
| <telerik:GridSortExpression FieldName="Todo_Date" SortOrder="Ascending" /> |
| </SortExpressions> |
| <DetailTables> |
| <telerik:GridTableView DataKeyNames="Todo_Date" Width="100%" |
| runat="server" AllowAutomaticUpdates="true" AutoGenerateColumns="false" EditMode="InPlace" |
| Name="Todo" HierarchyLoadMode="Client" CommandItemDisplay="Bottom" AllowAutomaticInserts="true"> |
| <ParentTableRelation> |
| <telerik:GridRelationFields DetailKeyField="Todo_Date" MasterKeyField="Todo_Date" /> |
| </ParentTableRelation> |
| <Columns> |
| <%-- <telerik:GridEditCommandColumn ButtonType="ImageButton" UniqueName="EditCommandColumn" HeaderText="Edit" > |
| <ItemStyle CssClass="MyImageButton" /> |
| </telerik:GridEditCommandColumn>--%> |
| <telerik:GridTemplateColumn DataField="Message" HeaderText="Task"> |
| <ItemTemplate> |
| <asp:Label runat="server" ID="Label1" Text='<%# Bind("Message") %>'></asp:Label> |
| </ItemTemplate> |
| <FooterTemplate> |
| <asp:LinkButton Text="Add new task" CommandName="<%# RadGrid.InitInsertCommandName %>" |
| runat="server" ID="LinkButton1"></asp:LinkButton> |
| </FooterTemplate> |
| <EditItemTemplate> |
| <asp:TextBox runat="Server" ID="TextBox1" Text='<%# Bind("Message") %>' Width="100%"></asp:TextBox> |
| </EditItemTemplate> |
| </telerik:GridTemplateColumn> |
| <telerik:GridDateTimeColumn DataField="Todo_Date" HeaderText="Due Date" DataFormatString="{0:d}" |
| HeaderStyle-Width="200px"> |
| </telerik:GridDateTimeColumn> |
| <telerik:GridTemplateColumn DataField="Type" HeaderText="Type" HeaderStyle-Width="200px"> |
| <ItemTemplate> |
| <asp:Label runat="Server" ID="Label2" Text='<%#Bind("Type") %>'></asp:Label> |
| </ItemTemplate> |
| <EditItemTemplate> |
| <telerik:RadComboBox runat="server" ID="priorityComboBox" SelectedValue='<%#Bind("Type") %>' |
| Skin="Office2007" Width="120px"> |
| <Items> |
| <telerik:RadComboBoxItem Text="Calls" Value="Calls" /> |
| <telerik:RadComboBoxItem Text="Other Things ToDo" Value="Other Things ToDo" /> |
| </Items> |
| </telerik:RadComboBox> |
| <asp:LinkButton ID="btnUpdate" Text="Save" runat="server" CommandName='<%# (Container is GridDataInsertItem) ? RadGrid.PerformInsertCommandName : RadGrid.UpdateCommandName %>'></asp:LinkButton> |
| <asp:LinkButton ID="btnCancel" Text="Cancel" runat="server" CommandName='<%# RadGrid.CancelCommandName %>'></asp:LinkButton> |
| </EditItemTemplate> |
| </telerik:GridTemplateColumn> |
| </Columns> |
| </telerik:GridTableView> |
| </DetailTables> |
| <ExpandCollapseColumn Visible="True"></ExpandCollapseColumn> |
| <Columns > |
| <telerik:GridDateTimeColumn DataField="Todo_Date" HeaderText="Todo_Date" DataFormatString="{0:D}" |
| HeaderStyle-Width="100%" > |
| </telerik:GridDateTimeColumn> |
| </Columns> |
| </MasterTableView> |
| </telerik:radgrid> |
Hello ,
I am using Hierarchical grid . On Inserting a new row in detailtable i am not able to exit the insert mode . inserted row is saved in database but it doesnt exit the insert mode .
for masterTable i could have used
RadGrid1.MasterTableView.IsItemInserted = false;
But how to do this in details table . I only want to insert record in detailtable .
Thank You
Vipin