| protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e) |
| { |
| if (e.CommandName == RadGrid.PerformInsertCommandName) |
| { |
| } |
| else if (e.CommandName == RadGrid.UpdateCommandName) |
| { |
| } |
| else if (e.CommandName == RadGrid.DeleteCommandName) |
| { |
| } |
| else if (e.CommandName == RadGrid.EditCommandName) |
| { |
| GridEditCommandColumn editColumn = (GridEditCommandColumn)RadGrid1.MasterTableView.GetColumn("EditCommandColumn"); |
| GridEditableItem item = (GridEditableItem)e.Item; |
| RadGrid Roles = (RadGrid)FindControlRecursive(this, "RadGrid2"); |
| DataTable dtTable2 = new DataTable(); |
| string conn2 = ConfigurationManager.ConnectionStrings["ConnectionString"].ToString(); |
| SqlDataAdapter sqladp2 = new SqlDataAdapter(); |
| SqlConnection sqlconn2 = new SqlConnection(conn2); |
| sqlconn2.Open(); |
| try |
| { |
| string selectQuery2 = "SELECT [RoleID], [Rolename] FROM [vw_UsersinRoles] WHERE [UserID] = " + e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["UserID"].ToString() + " ORDER BY [Username]"; |
| sqladp2.SelectCommand = new SqlCommand(selectQuery2, sqlconn2); |
| sqladp2.Fill(dtTable2); |
| Roles.DataSource = dtTable2; |
| Roles.DataBind(); |
| } |
| finally |
| { |
| sqlconn2.Close(); |
| } |
| } |
| } |
| public Control FindControlRecursive(Control root, string id) |
| { |
| if (root.ID == id) |
| { |
| return root; |
| } |
| foreach (Control c in root.Controls) |
| { |
| Control t = FindControlRecursive(c, id); |
| if (t != null) |
| { |
| return t; |
| } |
| } |
| return null; |
| } |
| <form id="form1" runat="server"> |
| <telerik:RadGrid ID="RadGrid1" runat="server" AllowFilteringByColumn="True" AllowPaging="True" |
| AllowSorting="True" GridLines="None" Width="623px" AutoGenerateColumns="false" |
| AllowAutomaticDeletes="True" AllowAutomaticInserts="True" AllowAutomaticUpdates="True" |
| GroupingSettings-CaseSensitive="false" PageSize="20" EnableLinqExpressions="False" |
| ShowStatusBar="True" OnPageIndexChanged="RadGrid1_PageIndexChanged" OnItemCommand="RadGrid1_ItemCommand" |
| OnSelectedIndexChanged="RadGrid1_SelectedIndexChanged"> |
| <MasterTableView ShowFooter="False" CommandItemSettings-AddNewRecordText="Add New Contact" |
| CommandItemDisplay="TopAndBottom" DataKeyNames="UserID"> |
| <CommandItemSettings AddNewRecordText="Add New Form"></CommandItemSettings> |
| <RowIndicatorColumn> |
| <HeaderStyle Width="20px"></HeaderStyle> |
| </RowIndicatorColumn> |
| <ExpandCollapseColumn> |
| <HeaderStyle Width="20px"></HeaderStyle> |
| </ExpandCollapseColumn> |
| <Columns> |
| <telerik:GridEditCommandColumn HeaderStyle-Width="15px" EditText="View / Edit"> |
| <HeaderStyle Width="15px"></HeaderStyle> |
| </telerik:GridEditCommandColumn> |
| <telerik:GridTemplateColumn UniqueName="DeleteColumn" ItemStyle-Width="16px" AllowFiltering="false"> |
| <HeaderStyle Width="16px" /> |
| <ItemTemplate> |
| <asp:ImageButton ID="imgbtnDelete" Width="14px" ToolTip="Delete Contact" runat="server" |
| CommandName="Delete" ImageUrl="~/images/recycle.jpg" OnClientClick="javascript:if(!confirm('This action will delete the selected contact. Are you sure?')){return false;}" /> |
| </ItemTemplate> |
| <ItemStyle Width="16px"></ItemStyle> |
| </telerik:GridTemplateColumn> |
| <telerik:GridBoundColumn DataField="Username" HeaderText="Username" SortExpression="Username" |
| UniqueName="Username"> |
| </telerik:GridBoundColumn> |
| </Columns> |
| <EditFormSettings CaptionFormatString="Edit details for User {0}" EditFormType="Template"> |
| <EditColumn UniqueName="EditCommandColumn1"> |
| </EditColumn> |
| <FormTemplate> |
| <table> |
| <tr> |
| <td> |
| <telerik:RadGrid ID="RadGrid2" runat="server" OnItemDataBound="RadGrid2_ItemDataBound" |
| AllowAutomaticDeletes="True" AllowAutomaticInserts="True" AutoGenerateColumns="False" |
| GridLines="None"> |
| </telerik:RadGrid> |
| </td> |
| </tr> |
| <tr> |
| <td> |
| <asp:Button ID="btnUpdate" Text='<%# (Container is GridEditFormInsertItem) ? "Insert" : "Update" %>' |
| runat="server" CommandName='<%# (Container is GridEditFormInsertItem) ? "PerformInsert" : "Update" %>'> |
| </asp:Button> <asp:Button CausesValidation="false" ID="btnEdit" Text="EditContact" |
| runat="server" CommandName="EditContact"></asp:Button> |
| <asp:Button ID="btnCancel" Text="Cancel" runat="server" CausesValidation="False" |
| CommandName="Cancel"></asp:Button> |
| </td> |
| </tr> |
| <table> |
| </FormTemplate> |
| </EditFormSettings> |
| <NoRecordsTemplate> |
| No Records</NoRecordsTemplate> |
| </MasterTableView> |
| <GroupingSettings CaseSensitive="False"></GroupingSettings> |
| </telerik:RadGrid> |
| <asp:ScriptManager ID="ScriptManager1" runat="server"> |
| </asp:ScriptManager> |
| </form> |