I having problems getting my Master/Detail grids to work. I have a page with two separate grids. Grid1 is the master and uses NeedDataSource to get it's data. Grid2 is the detail grid and will also use the NeedDataSource to get its data. Similar to this example:http://demos.telerik.com/aspnet-ajax/grid/examples/programming/selectedvalue/defaultcs.aspx. However, the example doesn't use NeedDataSource it uses client side declared datasources.
Grid1 (Master) is working fine(Retrieve data / Add/Update/Delete). But I'm not sure how to connect the Master grid to the Detail. I have turned on postbackonrowclick in Grid1. I was thinking I could call Grid2.Rebind() (Detail) in Grid1_NeedDataSource (Master) and pick up the Grid1.SelectedValue (Master's selected value) in Grid2_NeedDataSource (Detail) and pass it to my datalayer and everything will be good. But this doesn't work. I'm getting an object reference not found on Grid1.SelectedValue on page load. I'm guessing that's because nothing is selected on page load. ( I figured if nothing was selected it would return 0). What's the best way to get this to work??
Grids:
| <telerik:RadGrid ID="Grid1" runat="server" Width="95%" GridLines="None" |
| AutoGenerateColumns="False" PageSize="13" AllowPaging="True" AllowSorting="True" AllowMultiRowSelection="false" AllowMultiRowEdit="false" |
| OnUpdateCommand="ULNGrid_UpdateCommand" OnNeedDataSource="ULNGrid_NeedDataSource" OnItemDataBound="ULNGrid_ItemDataBound" |
| ShowStatusBar="true" ShowGroupPanel="false" OnInsertCommand="ULNGrid_InsertCommand" OnDeleteCommand="ULNGrid_DeleteCommand" Skin="Outlook" Visible="true" > |
| <MasterTableView DataKeyNames="Userlistnameid" Width="100%" CommandItemDisplay="TopAndBottom" EditMode="InPlace"> |
| <Columns> |
| <telerik:GridButtonColumn UniqueName="DeleteColumn" Text="Delete" CommandName="Delete" /> |
| <telerik:GridBoundColumn DataField="Name" HeaderText="Name" MaxLength="200" UniqueName="Name"> |
| <ItemStyle Width="400px" /> |
| </telerik:GridBoundColumn> |
| <telerik:GridDropDownColumn HeaderText="User List Type" UniqueName="UserListTypeddl" ListTextField="Name" ListValueField="Userlisttypeid" DataField="Userlisttypeid" |
| SortExpression="Userlisttypeid" DropDownControlType="DropDownList" FooterText="RadComboBox column footer" DataSourceID="SqlDsUserListTypeIdAll"> |
| </telerik:GridDropDownColumn> |
| <telerik:GridEditCommandColumn UpdateText="Update" UniqueName="EditCommandColumn" CancelText="Cancel" EditText="Edit"> |
| <HeaderStyle Width="85px"></HeaderStyle> |
| </telerik:GridEditCommandColumn> |
| </Columns> |
| </MasterTableView> |
| <ClientSettings EnablePostBackOnRowClick="true" > |
| <Selecting AllowRowSelect="True" /> |
| </ClientSettings> |
| </telerik:RadGrid> |
| //****************************************************************************** |
| <telerik:RadGrid ID="Grid2" runat="server" Width="95%" GridLines="None" |
| AutoGenerateColumns="False" PageSize="13" AllowPaging="True" AllowSorting="True" AllowMultiRowSelection="false" AllowMultiRowEdit="false" |
| OnUpdateCommand="ULCGrid_UpdateCommand" OnNeedDataSource="ULCGrid_NeedDataSource" OnItemDataBound="ULCGrid_ItemDataBound" |
| ShowStatusBar="true" ShowGroupPanel="false" OnInsertCommand="ULCGrid_InsertCommand" OnDeleteCommand="ULCGrid_DeleteCommand" Skin="Outlook" Visible="true" > |
| <MasterTableView DataKeyNames="Userlistcodeid" Width="100%" CommandItemDisplay="TopAndBottom" EditMode="InPlace"> |
| <Columns> |
| <telerik:GridButtonColumn UniqueName="DeleteColumn" Text="Delete" CommandName="Delete" /> |
| <telerik:GridBoundColumn DataField="Code" HeaderText="Code" MaxLength="32" UniqueName="Code"> |
| <ItemStyle Width="400px" /> |
| </telerik:GridBoundColumn> |
| <telerik:GridEditCommandColumn UpdateText="Update" UniqueName="EditCommandColumn" CancelText="Cancel" EditText="Edit"> |
| <HeaderStyle Width="85px"></HeaderStyle> |
| </telerik:GridEditCommandColumn> |
| </Columns> |
| </MasterTableView> |
| <ClientSettings > |
| <Selecting AllowRowSelect="True" /> |
| </ClientSettings> |
| </telerik:RadGrid> |
Code:
| Grid1: |
| public List<UserListName> GetULNList() |
| { |
| List<UserListName> ulnlist = UserListName.getAll(); |
| return ulnlist; |
| } |
| protected void Grid1_NeedDataSource(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e) |
| { |
| Grid1.DataSource = GetULNList(); |
| Grid2.Rebind() |
| } |
| //******************************************************************************* |
| public List<UserListCode> GetULCList() |
| { |
| string strulnid = Grid1.SelectedValue.ToString(); |
| int ulnid = 0; |
| Int32.TryParse(strulnid, out ulnid); |
| List<UserListCode> ulclist = UserListCode.getbyKey(ulnid); |
| return ulclist; |
| } |
| protected void Grid2_NeedDataSource(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e) |
| { |
| Grid2.DataSource = GetULCList(); |
| } |
Thanks