Select Row in one Grid, Get details in Another Grid

2 posts, 0 answers
  1. bslaght
    bslaght avatar
    184 posts
    Member since:
    Jun 2006

    Posted 07 Aug 2008 Link to this post

    Hi All,
    I have two grids.  In grid 1, I am returing results based on a search string.

    In grid 2 I am binding the details based on the "SelectedValue" in Grid 1.  However I would like to change it up, as this does not work well when more teh 1 result is retunred to grid 1 based on Search String. 

    Here is what I would like to happen:
    Search Table, rows get returned to Grid1.
    If only one row is return, thenselect it automatically and bind table 2 to the details.

    If more then one row gets returned to grid1, then select nothing.
    Allow Client Row Select
    Once Row is selected, rebind grid1 to only show that row and not any of the other original returned results, and rebind grid 2 with details of the now selected row in gird 1.

    If this could all happen in pretty AJAX, that would also be great!


    I have added my current code for evaluation:

    1 <%@ Page Title="" Language="VB" MasterPageFile="~/MasterPage.master" AutoEventWireup="false" 
    2     CodeFile="Copy of byAddress.aspx.vb" Inherits="test" %> 
    3  
    4 <%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %> 
    5 <%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxtoolkit" %> 
    6 <asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">  
    7 </asp:Content> 
    8 <asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">  
    9     <div id="searchblock">  
    10     <ajaxtoolkit:TextBoxWatermarkExtender ID="tbwm" runat="server"   
    11            TargetControlID="txtSearch" WatermarkText="99 Washington"   
    12            WatermarkCssClass="txtWatermark">  
    13        </ajaxtoolkit:TextBoxWatermarkExtender> 
    14         <asp:TextBox ID="txtSearch" runat="server"></asp:TextBox> 
    15         <asp:Button ID="btnSearch" runat="server" Text="Search"/>  
    16         <telerik:RadToolTip ID="RadToolTip1" runat="server" Animation="Fade"   
    17             AutoCloseDelay="5000" ShowDelay="100" Skin="Hay" TargetControlID="txtSearch"   
    18             Text="Please enter a street name without suffixes. (ex. Rd, Ave, St, Cr, Crs, Ln, etc.)"   
    19             VisibleOnPageLoad="True">  
    20         </telerik:RadToolTip> 
    21     </div> 
    22     <div class="tablehdr">  
    23         <h3> 
    24             Municipal Property Details</h3> 
    25             <p> 
    26     <asp:Label ID="lblError" runat="server" ForeColor="#FF3300"></asp:Label> 
    27         </p> 
    28     </div> 
    29     <telerik:RadCodeBlock ID="RadCodeBlock1" runat="server" > 
    30      <script type="text/javascript">  
    31             <!--  
    32                 function log(message)  
    33              {  
    34                  var log = document.getElementById("log");  
    35                  log.innerHTML += message + "<br/>";  
    36              }  
    37                 function GridCreated(sender, eventArgs)  
    38                 {  
    39                  var grid = $find("<%=RadGrid1.ClientID %>");  
    40                  //you can also use the sender argument keyword to reference the client grid object   
    41                     log("ClientID of server-side grid object is: " + grid.get_element().id);  
    42                 }  
    43  
    44  
    45                 function RowClick(sender, eventArgs)  
    46                 {  
    47                     var text = "";  
    48                     text += "Row was clicked";  
    49                     text += ", Index: " + eventArgs.get_itemIndexHierarchical();  
    50                     document.getElementById("OutPut").innerHTML = text;  
    51                     RadGrid2.Rebind();  
    52                 }  
    53  
    54                 function RowDblClick(sender, eventArgs)  
    55                 {  
    56                     var text = "";  
    57                     text += "Row was double clicked";  
    58                     text += ", Index: " + eventArgs.get_itemIndexHierarchical();  
    59                     document.getElementById("OutPut").innerHTML = text;  
    60                 }  
    61  
    62  
    63                 function RowSelected(sender, eventArgs)  
    64                 {  
    65                     var text = "";  
    66                     text += "Row with index: " + eventArgs.get_itemIndexHierarchical() + " was selected";  
    67                     document.getElementById("OutPut").innerHTML = text;  
    68                 }  
    69                   
    70                 function RowDeselected(sender, eventArgs)  
    71                 {  
    72                     var text = "";  
    73                     text += "Row with index: " + eventArgs.get_itemIndexHierarchical() + " was deselected";  
    74                     document.getElementById("OutPut").innerHTML = text;  
    75                 }  
    76  
    77                   
    78             --> 
    79     </script> 
    80  
    81     </telerik:RadCodeBlock> 
    82     <telerik:RadScriptBlock ID="RadScriptBlock1" runat="server" > 
    83     </telerik:RadScriptBlock> 
    84     <telerik:RadGrid ID="RadGrid1" runat="server" DataSourceID="dsGrid" Skin="Telerik" 
    85         GridLines="None">  
    86         <MasterTableView AutoGenerateColumns="False" DataSourceID="dsGrid" DataKeyNames="ROLL_NO">  
    87             <RowIndicatorColumn> 
    88                 <HeaderStyle Width="20px"></HeaderStyle> 
    89             </RowIndicatorColumn> 
    90             <ExpandCollapseColumn> 
    91                 <HeaderStyle Width="20px"></HeaderStyle> 
    92             </ExpandCollapseColumn> 
    93             <Columns> 
    94                 <telerik:GridBoundColumn DataField="ROLL_NO" HeaderText="Roll Number" SortExpression="ROLL_NO" 
    95                     UniqueName="ROLL_NO">  
    96                 </telerik:GridBoundColumn> 
    97                 <telerik:GridBoundColumn DataField="Address" HeaderText="Address" SortExpression="Address" 
    98                     UniqueName="Address" ReadOnly="True">  
    99                 </telerik:GridBoundColumn> 
    100                 <telerik:GridTemplateColumn HeaderText="Legal Description" UniqueName="TemplateColumn">  
    101                     <ItemTemplate> 
    102                         <asp:Label ID="Label58" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.LEGAL1") %>'>  
    103                         </asp:Label><br /> 
    104                         <asp:Label ID="Label1" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.LEGAL2") %>'>  
    105                         </asp:Label><br /> 
    106                         <asp:Label ID="Label2" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.LEGAL3") %>'>  
    107                         </asp:Label><br /> 
    108                         <asp:Label ID="Label3" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.LEGAL4") %>'>  
    109                         </asp:Label><br /> 
    110                         <asp:Label ID="Label4" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.LEGAL5") %>'>  
    111                         </asp:Label> 
    112                     </ItemTemplate> 
    113                 </telerik:GridTemplateColumn> 
    114                 <telerik:GridBoundColumn DataField="CLASS" HeaderText="Class" SortExpression="CLASS" 
    115                     UniqueName="CLASS">  
    116                 </telerik:GridBoundColumn> 
    117                 <telerik:GridBoundColumn DataField="ASSESSMENT" DataType="System.Decimal" HeaderText="Assesed Value" 
    118                     SortExpression="ASSESSMENT" UniqueName="ASSESSMENT" DataFormatString="{0:c}">  
    119                 </telerik:GridBoundColumn> 
    120                 <telerik:GridHyperLinkColumn HeaderText="More Details" NavigateUrl="details.aspx?txtSearch={0}" 
    121                     Text="View Details" UniqueName="column">  
    122                     <HeaderStyle HorizontalAlign="Center" /> 
    123                     <ItemStyle HorizontalAlign="Center" /> 
    124                 </telerik:GridHyperLinkColumn> 
    125             </Columns> 
    126         </MasterTableView> 
    127         <ClientSettings> 
    128             <Selecting AllowRowSelect="True" /> 
    129         </ClientSettings> 
    130         <FilterMenu EnableTheming="True">  
    131             <CollapseAnimation Type="OutQuint" Duration="200"></CollapseAnimation> 
    132         </FilterMenu> 
    133     </telerik:RadGrid> 
    134     <asp:SqlDataSource ID="dsGrid" runat="server" ConnectionString="<%$ ConnectionStrings:csProperty %>" 
    135         SelectCommand="SELECT DISTINCT txroll.ROLL_NO, CAST(txroll.STREET_NO AS varchar) + ' ' + txroll.STREET_NAME AS Address, txroll.LEGAL1, txroll.LEGAL2, txroll.LEGAL3, txroll.LEGAL4, txroll.LEGAL5, TX_ROLL_ASSESS.CLASS, TX_ROLL_ASSESS.ASSESSMENT, TX_ROLL_ASSESS.ASS_YEAR  
    136 FROM TX_ROLL txroll LEFT OUTER JOIN TX_ROLL_ASSESS ON txroll.ROLL_NO = TX_ROLL_ASSESS.ROLL_NO    
    137 WHERE CAST(txroll.STREET_NO AS varchar) + ' ' + txroll.STREET_NAME LIKE '%' + @ADDRESS + '%'   
    138 ORDER BY TX_ROLL_ASSESS.ASS_YEAR DESC"> 
    139         <SelectParameters> 
    140             <asp:ControlParameter Name="address" ControlID="txtSearch" Type="String" /> 
    141             <%--<asp:QueryStringParameter Name="ROLL_NO" QueryStringField="txtSearch" Type="String" />--%> 
    142         </SelectParameters> 
    143     </asp:SqlDataSource> 
    144     <br /> 
    145     <asp:Panel ID="pnlStructure" runat="server">  
    146         <div class="tablehdr">  
    147             <h3> 
    148                 Sturcture Details</h3> 
    149         </div> 
    150         <telerik:RadGrid ID="RadGrid2" runat="server" DataSourceID="dsStructure" GridLines="None" 
    151             Skin="Telerik">  
    152             <MasterTableView AutoGenerateColumns="False" DataSourceID="dsStructure" DataKeyNames="ROLL_NO">  
    153                 <RowIndicatorColumn> 
    154                     <HeaderStyle Width="20px" /> 
    155                 </RowIndicatorColumn> 
    156                 <ExpandCollapseColumn> 
    157                     <HeaderStyle Width="20px" /> 
    158                 </ExpandCollapseColumn> 
    159                 <Columns> 
    160                     <telerik:GridTemplateColumn UniqueName="TemplateColumn1" HeaderText="Construction">  
    161                         <ItemTemplate> 
    162                             CHAR OF CONST:<asp:Label ID="Label58" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.CHAR_OF_CONST") %>'>  
    163                             </asp:Label><br /> 
    164                             QUALITY:<asp:Label ID="Label1" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.QUALITY") %>'>  
    165                             </asp:Label><br /> 
    166                             SHAPE:<asp:Label ID="Label2" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.SHAPE") %>'>  
    167                             </asp:Label><br /> 
    168                             YEAR BUILT:<asp:Label ID="Label3" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.YEAR_BUILT") %>'>  
    169                             </asp:Label><br /> 
    170                             YEAR BUILT CODE:<asp:Label ID="Label4" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.YEAR_BUILT_CODE") %>'>  
    171                             </asp:Label></ItemTemplate>  
    172                     </telerik:GridTemplateColumn> 
    173                     <telerik:GridTemplateColumn UniqueName="TemplateColumn2" HeaderText="Building">  
    174                         <ItemTemplate> 
    175                             CONDITION:<asp:Label ID="Label59" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.CONDITION") %>'>  
    176                             </asp:Label><br /> 
    177                             FULL STORYS:<asp:Label ID="Label1" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.FULL_STOREYS") %>'>  
    178                             </asp:Label><br /> 
    179                             PART STORYS:<asp:Label ID="Label2" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.PART_STOREYS") %>'>  
    180                             </asp:Label><br /> 
    181                             HEIGHT EFF DATE:<asp:Label ID="Label3" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.HEIGHT_EFF_DATE_S") %>'>  
    182                             </asp:Label><br /> 
    183                             SPLIT:<asp:Label ID="Label4" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.SPLIT") %>'>  
    184                             </asp:Label></ItemTemplate>  
    185                     </telerik:GridTemplateColumn> 
    186                     <telerik:GridTemplateColumn UniqueName="TemplateColumn3" HeaderText="Area">  
    187                         <ItemTemplate> 
    188                             GROSS AREA:<asp:Label ID="Label59" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.GROSS_AREA") %>'>  
    189                             </asp:Label><br /> 
    190                             TOTAL BASEMENT:<asp:Label ID="Label1" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.TOTAL_BASEMENT") %>'>  
    191                             </asp:Label><br /> 
    192                             FINISH BASEMENT:<asp:Label ID="Label2" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.FINISH_BASEMENT") %>'>  
    193                             </asp:Label><br /> 
    194                             FINISH BASEMENT:<asp:Label ID="Label3" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.FINISH_BASEMENT_TY") %>'>  
    195                             </asp:Label><br /> 
    196                             </asp:Label></ItemTemplate>  
    197                     </telerik:GridTemplateColumn> 
    198                     <telerik:GridTemplateColumn UniqueName="TemplateColumn4" HeaderText="Features">  
    199                         <ItemTemplate> 
    200                             FULL BATHS:<asp:Label ID="Label59" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.FULL_BATHS") %>'>  
    201                             </asp:Label><br /> 
    202                             HALF BATHS:<asp:Label ID="Label1" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.HALF_BATHS") %>'>  
    203                             </asp:Label><br /> 
    204                             # BEDROOMS:<asp:Label ID="Label2" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.NO_OF_BEDROOMS") %>'>  
    205                             </asp:Label><br /> 
    206                             # FIREPLACES:<asp:Label ID="Label3" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.NO_OF_FIREPLACES") %>'>  
    207                             </asp:Label><br /> 
    208                             HEATING TYPE:<asp:Label ID="Label5" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.HEATING_TYPE") %>'>  
    209                             </asp:Label><br /> 
    210                             AIR CONDITIONING:<asp:Label ID="Label6" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.AIR_CONDITIONING") %>'>  
    211                             </asp:Label><br /> 
    212                             </asp:Label></ItemTemplate>  
    213                     </telerik:GridTemplateColumn> 
    214                     <telerik:GridTemplateColumn UniqueName="TemplateColumn" HeaderText="Garage">  
    215                         <ItemTemplate> 
    216                             GARAGE TYPE:<asp:Label ID="Label59" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.GARAGE_TYPE") %>'>  
    217                             </asp:Label><br /> 
    218                             GARAGE SPACES:<asp:Label ID="Label1" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.GARAGE_SPACES") %>'>  
    219                             </asp:Label><br /> 
    220                             STRUCTURE CODE:<asp:Label ID="Label2" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.STRUCT_CODE") %>'>  
    221                             </asp:Label></ItemTemplate>  
    222                     </telerik:GridTemplateColumn> 
    223                 </Columns> 
    224             </MasterTableView> 
    225             <FilterMenu EnableTheming="True">  
    226                 <CollapseAnimation Duration="200" Type="OutQuint" /> 
    227             </FilterMenu> 
    228         </telerik:RadGrid><ajaxtoolkit:CollapsiblePanelExtender ID="cpe" runat="Server" TargetControlID="pnlStructure" 
    229             CollapsedSize="0" Collapsed="True" ExpandControlID="RadGrid1" CollapseControlID="RadGrid1" 
    230             AutoCollapse="False" AutoExpand="False" ScrollContents="False" ImageControlID="imgLegal" 
    231             ExpandedImage="~/lib/img/collapse.jpg" CollapsedImage="~/lib/img/expand.jpg" 
    232             ExpandDirection="Vertical" SuppressPostBack="true" /> 
    233         </ajaxtoolkit:CollapsiblePanelExtender><asp:ImageButton ID="imgPrint" runat="server" ImageUrl="lib/img/printer.png" 
    234             ImageAlign="Middle" AutoPostBack="False" CausesValidation="False" CssClass="imgPrint" /><asp:LinkButton  
    235                 ID="lnkPrint" runat="server" CssClass="lnkPrint">Print Now</asp:LinkButton> 
    236         <asp:SqlDataSource ID="dsStructure" runat="server" ConnectionString="<%$ ConnectionStrings:csProperty %>" 
    237             SelectCommand="SELECT [ROLL_NO], [CHAR_OF_CONST], [QUALITY], [SHAPE], [YEAR_BUILT], [YEAR_BUILT_CODE], [CONDITION], [FULL_STOREYS], [PART_STOREYS], [HEIGHT_EFF_DATE_S], [SPLIT], [GROSS_AREA], [TOTAL_BASEMENT], [FINISH_BASEMENT], [FINISH_BASEMENT_TY], [FULL_BATHS], [HALF_BATHS], [NO_OF_BEDROOMS], [NO_OF_FIREPLACES], [HEATING_TYPE], [AIR_CONDITIONING], [GARAGE_TYPE], [GARAGE_SPACES], [STRUCT_CODE] FROM [TX_STRUCT] WHERE ([ROLL_NO] = @ROLL_NO) ORDER BY [CHAR_OF_CONST] DESC">  
    238             <SelectParameters> 
    239                 <asp:ControlParameter ControlID="RadGrid1" Name="ROLL_NO" PropertyName="SelectedValue" 
    240                     Type="string" /> 
    241             </SelectParameters> 
    242         </asp:SqlDataSource> 
    243     </asp:Panel> 
    244 </asp:Content> 


    1 Imports System  
    2 Imports System.Web.UI.WebControls  
    3 Imports Telerik.Web.UI  
    4 Imports System.Data.SqlClient  
    5  
    6 Partial Class test  
    7     Inherits System.Web.UI.Page  
    8     Protected Sub Page_Load(ByVal sender As ObjectByVal e As System.EventArgs) Handles Me.Load  
    9         imgPrint.Attributes.Add("onclick""javascript:window.print(); return false;")  
    10         lnkPrint.Attributes.Add("onclick""javascript:window.print(); return false;")  
    11  
    12     End Sub 
    13  
    14     Protected Sub RadGrid1_DataBound(ByVal sender As ObjectByVal e As System.EventArgs) Handles RadGrid1.DataBound  
    15         If Page.IsPostBack Then 
    16             Try 
    17                 RadGrid1.Items(0).Selected = True 
    18                 RadGrid2.MasterTableView.Rebind()  
    19             Catch ex As IndexOutOfRangeException  
    20                 'MsgBox(ex.Message)  
    21                 lblError.Text = "Your Search: " 
    22                 lblError.Text += txtSearch.Text  
    23                 lblError.Text += " did not find any matches.  Please try again." 
    24             Catch ex As Exception  
    25                 'MsgBox(ex.Message)  
    26                 'lblError.Text = "An error has occured/"  
    27                 'lblError.Text += ex.Message  
    28                 lblError.Text = "Your Search: " 
    29                 lblError.Text += txtSearch.Text  
    30                 lblError.Text += " did not find any matches.  Please try again." 
    31             End Try 
    32         End If 
    33     End Sub 
    34 End Class 
    35  

    Thanks for any help!
  2. Yavor
    Admin
    Yavor avatar
    11 posts

    Posted 12 Aug 2008 Link to this post

    Hi bslaght,

    One possible implementation, which caters for your scenario, would be as shown in this code example. Additionally, as an add-on to the code in the sample, you can use the PreRender event handler for the 1st grid. From there, depending on the RadGrid1.MasterTableView.Items count, you can pre-select the first item. This will ensure that the data related to the 1st record is rendered in the other grid.
    I hope this suggestion help.

    Kind regards,
    Yavor
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top