DataBind Grid based on Search DropDown Option

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

    Posted 24 Jul 2008 Link to this post

    I have a grid that I need to databind on button click based on what is chosen in a dropdown list and what is typed in a textbox.

    However the dropdown and textbox are in teh master page, while the grid is on a content page.

    How do I accomplish this?  I have my code started as follows, I know my SQL SELECT is wrong because basically I need to say

    IF ddllist = rollno then ("USE this SQL SELECT for ROLL_NO")
    ELSEIF ddlist = address then ("USE this SQL SELECT for ADDRESS")
    ELSEIF ddlist = legal then ("USE this SQL SELECT for LEGAL")
    END IF

    However I don't know how to bind a grid this way.  You will see I ma using standard asp controls at this point because I am waiting for Q2 Ajax controls so that postbacks can be surpressed.   Any help or samples would be awesome!

    Thanks,
    Brett


    MasterPage.vb
    Protected Sub btnSearch_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSearch.Click
    Dim gvpd As DataGrid = TryCast(Page.FindControl("gvPropertyDetails"), DataGrid)
    gvpd.DataBind(based on my drop and text box?????)
    End Sub

    MasterPage ASPX:
    <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True">
    <asp:ListItem Selected="True" Value="rollno">Roll No.</asp:ListItem>
    <asp:ListItem Value="address">Civic\St. Address</asp:ListItem>
    <asp:ListItem Value="legaldesc">Legal Derscription</asp:ListItem>
    </asp:DropDownList>
    &nbsp;
    <asp:TextBox ID="txtSearch" runat="server"></asp:TextBox>
    &nbsp;
    <asp:Button ID="btnSearch" runat="server" Text="Search" />

    Content Page ASPX:

    1 <asp:GridView ID="gvPropertyDetails" runat="server" AutoGenerateColumns="False" DataSourceID="dsProperty" 
    2         CellPadding="4" Width="100%" DataKeyNames="ROLL_NO" ForeColor="#333333"   
    3         GridLines="None">  
    4         <RowStyle BackColor="#E3EAEB" /> 
    5         <Columns> 
    6             <asp:BoundField DataField="ROLL_NO" HeaderText="Roll Number" SortExpression="ROLL_NO" /> 
    7             <asp:BoundField DataField="Address" HeaderText="Address" ReadOnly="True" SortExpression="Address" /> 
    8             <asp:TemplateField HeaderText="Legal Description">  
    9                 <ItemTemplate> 
    10                     <asp:Label ID="Label58" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.LEGAL1") %>'>  
    11                     </asp:Label><br /> 
    12                     <asp:Label ID="Label1" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.LEGAL2") %>'>  
    13                     </asp:Label><br /> 
    14                     <asp:Label ID="Label2" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.LEGAL3") %>'>  
    15                     </asp:Label><br /> 
    16                     <asp:Label ID="Label3" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.LEGAL4") %>'>  
    17                     </asp:Label><br /> 
    18                     <asp:Label ID="Label4" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.LEGAL5") %>'>  
    19                     </asp:Label></ItemTemplate>  
    20             </asp:TemplateField> 
    21             <asp:BoundField DataField="CLASS" HeaderText="Class" SortExpression="CLASS" /> 
    22             <asp:BoundField DataField="ASSESSMENT" HeaderText="Assessed Value"   
    23                 SortExpression="ASSESSMENT" DataFormatString="{0:c}" />    
    24             <asp:HyperLinkField DataNavigateUrlFields="roll_no"   
    25                 DataNavigateUrlFormatString="propdetails.aspx?roll_no={0}"   
    26                 HeaderText="Property Details" Text="More Details"   
    27                 ItemStyle-HorizontalAlign="Center" > 
    28 <ItemStyle HorizontalAlign="Center"></ItemStyle> 
    29             </asp:HyperLinkField> 
    30         </Columns> 
    31         <FooterStyle BackColor="#1C5E55" ForeColor="White" Font-Bold="True" /> 
    32         <PagerStyle BackColor="#666666" ForeColor="White" HorizontalAlign="Center" /> 
    33         <SelectedRowStyle BackColor="#C5BBAF" Font-Bold="True" ForeColor="#333333" /> 
    34         <HeaderStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" /> 
    35         <EditRowStyle BackColor="#7C6F57" /> 
    36         <AlternatingRowStyle BackColor="White" /> 
    37     </asp:GridView> 
    38     <asp:SqlDataSource ID="dsProperty" runat="server" ConnectionString="<%$ ConnectionStrings:csProperty %>" 
    39         SelectCommand="SELECT TOP 1 TX_ROLL.ROLL_NO, CAST(TX_ROLL.STREET_NO AS varchar) + ' ' + TX_ROLL.STREET_NAME AS Address, TX_ROLL.LEGAL1, TX_ROLL.LEGAL2, TX_ROLL.LEGAL3, TX_ROLL.LEGAL4, TX_ROLL.LEGAL5, TX_ROLL_ASSESS.CLASS, TX_ROLL_ASSESS.ASSESSMENT FROM TX_ROLL LEFT OUTER JOIN TX_ROLL_ASSESS ON TX_ROLL.ROLL_NO = TX_ROLL_ASSESS.ROLL_NO WHERE (TX_ROLL.ROLL_NO LIKE @txtSearch or Address LIKE @txtSearch or TX_ROLL.LEGAL1 LIKE @txtSearch OR TX_ROLL.LEGAL2 LIKE @txtSearch OR TX_ROLL.LEGAL3 LIKE @txtSearch) ORDER BY TX_ROLL_ASSESS.ASS_YEAR DESC">  
    40     </asp:SqlDataSource> 
    41     <selectparameters> 
    42                 <asp:Parameter Name="txtSearch" Type="String"/> 

  2. Richard
    Richard avatar
    60 posts
    Member since:
    Feb 2008

    Posted 24 Jul 2008 Link to this post

    Before you do the DataBind can't you just set the SelectCommand of your datasource to the new SQL string?
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. bslaght
    bslaght avatar
    184 posts
    Member since:
    Jun 2006

    Posted 24 Jul 2008 Link to this post

    Possibly, I am still pretty new to all this.  Do you have an example of how to do that?
  5. Richard
    Richard avatar
    60 posts
    Member since:
    Feb 2008

    Posted 24 Jul 2008 Link to this post

    You should be able to just get a reference to your SQLDataSource object and set its SelectCommand property...

    Dim myNewSQLString As String

    IF ddllist = rollno then (myNewSQLString  = "USE this SQL SELECT for ROLL_NO")
    ELSEIF ddlist = address then (
    myNewSQLString  = "USE this SQL SELECT for ADDRESS")
    ELSEIF ddlist = legal then (
    myNewSQLString  = "USE this SQL SELECT for LEGAL")
    END IF

    Dim sqlds As SQLDataSource = TryCast(Page.FindControl("dsProperty"), SQLDataSource)
    sqlds.SelectCommand = myNewSQLString

    Dim gvpd As DataGrid = TryCast(Page.FindControl("gvPropertyDetails"), DataGrid)
    gvpd.DataBind()

  6. bslaght
    bslaght avatar
    184 posts
    Member since:
    Jun 2006

    Posted 24 Jul 2008 Link to this post

    Thanks for the sample Richard, however I guess I am still not getting it.
    I am using your code in the button click event of my search button.  But all I am geting is an error: Object reference not set to an instance of an object. after clicking the search button, I am guessing this is because we are not handling the parameters, however I am unsure how to do that also, please have a look if you don't mind.

    Here is my updated page and codes:
    vb.net

    1 Imports System  
    2 Imports System.Web.UI.WebControls  
    3 Imports Telerik.Web  
    4  
    5 Partial Class test  
    6     Inherits System.Web.UI.Page  
    7     Protected Sub Page_Load(ByVal sender As ObjectByVal e As System.EventArgs) Handles Me.Load  
    8         imgPrint.Attributes.Add("onclick""javascript:window.print(); return false;")  
    9         lnkPrint.Attributes.Add("onclick""javascript:window.print(); return false;")  
    10     End Sub 
    11  
    12     Protected Sub RadGrid1_PreRender(ByVal sender As ObjectByVal e As System.EventArgs) Handles RadGrid1.PreRender  
    13         'change selection and add a response script to rebind the second grid  
    14         RadGrid1.Items(0).Selected = True 
    15         RadGrid2.MasterTableView.Rebind()  
    16     End Sub 
    17  
    18     Protected Sub btnSearch_Click(ByVal sender As ObjectByVal e As System.EventArgs) Handles btnSearch.Click  
    19         Dim myNewSQLString As String 
    20  
    21         If ddlSearch.SelectedValue = "rollno" Then 
    22             myNewSQLString = "SELECT TOP 1 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" _  
    23                                 & "FROM TX_ROLL txroll LEFT OUTER JOIN TX_ROLL_ASSESS ON txroll.ROLL_NO = TX_ROLL_ASSESS.ROLL_NO" _  
    24                                 & "WHERE txroll.ROLL_NO = @ROLL_NO" _  
    25                                 & "ORDER BY TX_ROLL_ASSESS.ASS_YEAR DESC" 
    26  
    27             'ElseIf ddlSearch.SelectedValue = "address" Then  
    28             '    myNewSQLString = "USE this SQL SELECT for ADDRESS"  
    29             'ElseIf ddlSearch.SelectedValue = "legal" Then  
    30             '    myNewSQLString = "USE this SQL SELECT for LEGAL"  
    31         End If 
    32  
    33         Dim sqlds As SqlDataSource = TryCast(Page.FindControl("dsGrid"), SqlDataSource)  
    34         sqlds.SelectCommand = myNewSQLString  
    35  
    36         Dim rgpd As DataGrid = TryCast(Page.FindControl("RadGrid1"), DataGrid)  
    37         rgpd.DataBind()  
    38     End Sub 
    39 End Class 

    asp.net
    1 <%@ Page Title="" Language="VB" MasterPageFile="~/MasterPage.master" AutoEventWireup="false" 
    2     CodeFile="details.aspx.vb" Inherits="test" %> 
    3  
    4 <%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %> 
    5 <%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %> 
    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         <asp:DropDownList ID="ddlSearch" runat="server" AutoPostBack="True">  
    11             <asp:ListItem Selected="True" Value="rollno">Roll No.</asp:ListItem> 
    12             <asp:ListItem Value="address">Civic\St. Address</asp:ListItem> 
    13             <asp:ListItem Value="legal">Legal Derscription</asp:ListItem> 
    14         </asp:DropDownList> 
    15         <asp:TextBox ID="txtSearch" runat="server" va>401015084000000</asp:TextBox> 
    16         <asp:Button ID="btnSearch" runat="server" Text="Search" /> 
    17     </div> 
    18     <div class="tablehdr">  
    19         <h3> 
    20             Municipal Property Details</h3> 
    21     </div> 
    22     <telerik:RadGrid ID="RadGrid1" runat="server" DataSourceID="dsGrid" Skin="Telerik" 
    23         GridLines="None" OnPreRender="RadGrid1_PreRender">  
    24         <MasterTableView AutoGenerateColumns="False" DataSourceID="dsGrid" DataKeyNames="ROLL_NO">  
    25             <RowIndicatorColumn> 
    26                 <HeaderStyle Width="20px"></HeaderStyle> 
    27             </RowIndicatorColumn> 
    28             <ExpandCollapseColumn> 
    29                 <HeaderStyle Width="20px"></HeaderStyle> 
    30             </ExpandCollapseColumn> 
    31             <Columns> 
    32                 <telerik:GridBoundColumn DataField="ROLL_NO" HeaderText="Roll Number" SortExpression="ROLL_NO" 
    33                     UniqueName="ROLL_NO">  
    34                 </telerik:GridBoundColumn> 
    35                 <telerik:GridBoundColumn DataField="Address" HeaderText="Address" SortExpression="Address" 
    36                     UniqueName="Address" ReadOnly="True">  
    37                 </telerik:GridBoundColumn> 
    38                 <%--<telerik:GridBoundColumn DataField="LEGAL1" HeaderText="LEGAL1"   
    39             SortExpression="LEGAL1" UniqueName="LEGAL1">  
    40         </telerik:GridBoundColumn> 
    41         <telerik:GridBoundColumn DataField="LEGAL2" HeaderText="LEGAL2"   
    42             SortExpression="LEGAL2" UniqueName="LEGAL2">  
    43         </telerik:GridBoundColumn> 
    44         <telerik:GridBoundColumn DataField="LEGAL3" HeaderText="LEGAL3"   
    45             SortExpression="LEGAL3" UniqueName="LEGAL3">  
    46         </telerik:GridBoundColumn> 
    47         <telerik:GridBoundColumn DataField="LEGAL4" HeaderText="LEGAL4"   
    48             SortExpression="LEGAL4" UniqueName="LEGAL4">  
    49         </telerik:GridBoundColumn> 
    50         <telerik:GridBoundColumn DataField="LEGAL5" HeaderText="LEGAL5"   
    51             SortExpression="LEGAL5" UniqueName="LEGAL5">  
    52         </telerik:GridBoundColumn>--%> 
    53                 <telerik:GridTemplateColumn HeaderText="Legal Description" UniqueName="TemplateColumn">  
    54                     <ItemTemplate> 
    55                         <asp:Label ID="Label58" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.LEGAL1") %>'>  
    56    
    57                         </asp:Label><br /> 
    58                         <asp:Label ID="Label1" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.LEGAL2") %>'>  
    59    
    60                         </asp:Label><br /> 
    61                         <asp:Label ID="Label2" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.LEGAL3") %>'>  
    62    
    63                         </asp:Label><br /> 
    64                         <asp:Label ID="Label3" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.LEGAL4") %>'>  
    65    
    66                         </asp:Label><br /> 
    67                         <asp:Label ID="Label4" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.LEGAL5") %>'>  
    68    
    69                         </asp:Label> 
    70                     </ItemTemplate> 
    71                 </telerik:GridTemplateColumn> 
    72                 <telerik:GridBoundColumn DataField="CLASS" HeaderText="Class" SortExpression="CLASS" 
    73                     UniqueName="CLASS">  
    74                 </telerik:GridBoundColumn> 
    75                 <telerik:GridBoundColumn DataField="ASSESSMENT" DataType="System.Decimal" HeaderText="Assesed Value" 
    76                     SortExpression="ASSESSMENT" UniqueName="ASSESSMENT" DataFormatString="{0:c}">  
    77                 </telerik:GridBoundColumn> 
    78                 <telerik:GridHyperLinkColumn HeaderText="More Details" NavigateUrl="details.aspx?txtSearch={0}" 
    79                     Text="View Details" UniqueName="column">  
    80                     <HeaderStyle HorizontalAlign="Center" /> 
    81                     <ItemStyle HorizontalAlign="Center" /> 
    82                 </telerik:GridHyperLinkColumn> 
    83             </Columns> 
    84         </MasterTableView> 
    85         <FilterMenu EnableTheming="True">  
    86             <CollapseAnimation Type="OutQuint" Duration="200"></CollapseAnimation> 
    87         </FilterMenu> 
    88     </telerik:RadGrid> 
    89     <asp:SqlDataSource ID="dsGrid" runat="server" ConnectionString="<%$ ConnectionStrings:csProperty %>" 
    90         SelectCommand="SELECT TOP 1 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  
    91 FROM TX_ROLL txroll LEFT OUTER JOIN TX_ROLL_ASSESS ON txroll.ROLL_NO = TX_ROLL_ASSESS.ROLL_NO    
    92 WHERE txroll.ROLL_NO = @ROLL_NO  
    93 ORDER BY TX_ROLL_ASSESS.ASS_YEAR DESC"> 
    94         <SelectParameters> 
    95             <asp:ControlParameter Name="ROLL_NO" ControlID="txtSearch" Type="String" /> 
    96             <%--<asp:QueryStringParameter Name="ROLL_NO" QueryStringField="txtSearch" Type="String" />--%> 
    97         </SelectParameters> 
    98     </asp:SqlDataSource> 
    99     <br /> 
    100     <asp:Panel ID="pnlStructure" runat="server">  
    101         <div class="tablehdr">  
    102             <h3> 
    103                 Sturcture Details</h3> 
    104         </div> 
    105         <telerik:RadGrid ID="RadGrid2" runat="server" DataSourceID="dsStructure" GridLines="None" 
    106             Skin="Telerik">  
    107             <MasterTableView AutoGenerateColumns="False" DataSourceID="dsStructure" DataKeyNames="ROLL_NO">  
    108                 <RowIndicatorColumn> 
    109                     <HeaderStyle Width="20px" /> 
    110                 </RowIndicatorColumn> 
    111                 <ExpandCollapseColumn> 
    112                     <HeaderStyle Width="20px" /> 
    113                 </ExpandCollapseColumn> 
    114                 <Columns> 
    115                     <telerik:GridTemplateColumn UniqueName="TemplateColumn1" HeaderText="Construction">  
    116                         <ItemTemplate> 
    117                             CHAR OF CONST:<asp:Label ID="Label58" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.CHAR_OF_CONST") %>'>  
    118    
    119                             </asp:Label><br /> 
    120                             QUALITY:<asp:Label ID="Label1" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.QUALITY") %>'>  
    121    
    122                             </asp:Label><br /> 
    123                             SHAPE:<asp:Label ID="Label2" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.SHAPE") %>'>  
    124    
    125                             </asp:Label><br /> 
    126                             YEAR BUILT:<asp:Label ID="Label3" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.YEAR_BUILT") %>'>  
    127    
    128                             </asp:Label><br /> 
    129                             YEAR BUILT CODE:<asp:Label ID="Label4" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.YEAR_BUILT_CODE") %>'>  
    130    
    131                             </asp:Label></ItemTemplate>  
    132                     </telerik:GridTemplateColumn> 
    133                     <telerik:GridTemplateColumn UniqueName="TemplateColumn2" HeaderText="Building">  
    134                         <ItemTemplate> 
    135                             CONDITION:<asp:Label ID="Label59" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.CONDITION") %>'>  
    136    
    137                             </asp:Label><br /> 
    138                             FULL STORYS:<asp:Label ID="Label1" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.FULL_STOREYS") %>'>  
    139    
    140                             </asp:Label><br /> 
    141                             PART STORYS:<asp:Label ID="Label2" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.PART_STOREYS") %>'>  
    142    
    143                             </asp:Label><br /> 
    144                             HEIGHT EFF DATE:<asp:Label ID="Label3" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.HEIGHT_EFF_DATE_S") %>'>  
    145    
    146                             </asp:Label><br /> 
    147                             SPLIT:<asp:Label ID="Label4" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.SPLIT") %>'>  
    148    
    149                             </asp:Label></ItemTemplate>  
    150                     </telerik:GridTemplateColumn> 
    151                     <telerik:GridTemplateColumn UniqueName="TemplateColumn3" HeaderText="Area">  
    152                         <ItemTemplate> 
    153                             GROSS AREA:<asp:Label ID="Label59" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.GROSS_AREA") %>'>  
    154    
    155                             </asp:Label><br /> 
    156                             TOTAL BASEMENT:<asp:Label ID="Label1" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.TOTAL_BASEMENT") %>'>  
    157    
    158                             </asp:Label><br /> 
    159                             FINISH BASEMENT:<asp:Label ID="Label2" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.FINISH_BASEMENT") %>'>  
    160    
    161                             </asp:Label><br /> 
    162                             FINISH BASEMENT:<asp:Label ID="Label3" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.FINISH_BASEMENT_TY") %>'>  
    163    
    164                             </asp:Label><br /> 
    165                             </asp:Label></ItemTemplate>  
    166                     </telerik:GridTemplateColumn> 
    167                     <telerik:GridTemplateColumn UniqueName="TemplateColumn4" HeaderText="Features">  
    168                         <ItemTemplate> 
    169                             FULL BATHS:<asp:Label ID="Label59" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.FULL_BATHS") %>'>  
    170    
    171    
    172                               
    173  
    174                                
    175    
    176                               
    177                             </asp:Label><br /> 
    178                             HALF BATHS:<asp:Label ID="Label1" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.HALF_BATHS") %>'>  
    179    
    180    
    181                               
    182  
    183                                
    184    
    185                               
    186                             </asp:Label><br /> 
    187                             # BEDROOMS:<asp:Label ID="Label2" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.NO_OF_BEDROOMS") %>'>  
    188    
    189    
    190                               
    191  
    192                                
    193    
    194                               
    195                             </asp:Label><br /> 
    196                             # FIREPLACES:<asp:Label ID="Label3" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.NO_OF_FIREPLACES") %>'>  
    197    
    198    
    199                               
    200  
    201                                
    202    
    203                               
    204                             </asp:Label><br /> 
    205                             HEATING TYPE:<asp:Label ID="Label5" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.HEATING_TYPE") %>'>  
    206    
    207    
    208                               
    209  
    210                                
    211    
    212                               
    213                             </asp:Label><br /> 
    214                             AIR CONDITIONING:<asp:Label ID="Label6" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.AIR_CONDITIONING") %>'>  
    215    
    216    
    217                               
    218  
    219                                
    220    
    221                               
    222                             </asp:Label><br /> 
    223                             </asp:Label></ItemTemplate>  
    224                     </telerik:GridTemplateColumn> 
    225                     <telerik:GridTemplateColumn UniqueName="TemplateColumn" HeaderText="Garage">  
    226                         <ItemTemplate> 
    227                             GARAGE TYPE:<asp:Label ID="Label59" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.GARAGE_TYPE") %>'>  
    228    
    229    
    230                               
    231  
    232                                
    233    
    234                               
    235                             </asp:Label><br /> 
    236                             GARAGE SPACES:<asp:Label ID="Label1" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.GARAGE_SPACES") %>'>  
    237    
    238    
    239                               
    240  
    241                                
    242    
    243                               
    244                             </asp:Label><br /> 
    245                             STRUCTURE CODE:<asp:Label ID="Label2" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.STRUCT_CODE") %>'>  
    246    
    247                             </asp:Label></ItemTemplate>  
    248                     </telerik:GridTemplateColumn> 
    249                 </Columns> 
    250             </MasterTableView> 
    251             <FilterMenu EnableTheming="True">  
    252                 <CollapseAnimation Duration="200" Type="OutQuint" /> 
    253             </FilterMenu> 
    254         </telerik:RadGrid><cc1:CollapsiblePanelExtender ID="cpe" runat="Server" TargetControlID="pnlStructure" 
    255             CollapsedSize="0" Collapsed="True" ExpandControlID="RadGrid1" CollapseControlID="RadGrid1" 
    256             AutoCollapse="False" AutoExpand="False" ScrollContents="False" ImageControlID="imgLegal" 
    257             ExpandedImage="~/lib/img/collapse.jpg" CollapsedImage="~/lib/img/expand.jpg" 
    258             ExpandDirection="Vertical" SuppressPostBack="true" /> 
    259         </cc1:CollapsiblePanelExtender><asp:ImageButton ID="imgPrint" runat="server" ImageUrl="lib/img/printer.png" 
    260             ImageAlign="Middle" AutoPostBack="False" CausesValidation="False" CssClass="imgPrint" /><asp:LinkButton  
    261                 ID="lnkPrint" runat="server" CssClass="lnkPrint">Print Now</asp:LinkButton> 
    262         <asp:SqlDataSource ID="dsStructure" runat="server" ConnectionString="<%$ ConnectionStrings:csProperty %>" 
    263             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">  
    264             <SelectParameters> 
    265                 <asp:ControlParameter ControlID="RadGrid1" Name="ROLL_NO" PropertyName="SelectedValue" 
    266                     Type="string" /> 
    267             </SelectParameters> 
    268         </asp:SqlDataSource> 
    269     </asp:Panel> 
    270 </asp:Content> 
    271  

    Again, I thank you for anymore help you can provide.
    Brett
  7. Richard
    Richard avatar
    60 posts
    Member since:
    Feb 2008

    Posted 25 Jul 2008 Link to this post

    My apologies - I should have tested first.  I assumed that your

    TryCast(Page.FindControl("gvPropertyDetails"), DataGrid)

    syntax was working.  What you actually need to do to access the controls from the master page is:

    TryCast(Page.Form.FindControl("ContentPlaceholderID").FindControl("gvPropertyDetails"), DataGrid)
  8. bslaght
    bslaght avatar
    184 posts
    Member since:
    Jun 2006

    Posted 28 Jul 2008 Link to this post

    Hi Richard,
        Thanks for the update, I actually moved it all to my content page for testing so I will use you masterpage code later on, once I get this working.  However I am still haivng difficulties getting this going.

    My New Error:
    BC30516: Overload resolution failed because no accessible 'DataBind' accepts this number of arguments.

    I have updated my code as follows, how do I reference myNewSqlString???

    Protected Sub btnSearch_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSearch.Click

    Dim myNewSQLString As String

    Dim gvpd As DataGrid = TryCast(Page.FindControl("gvPropertyDetails"), DataGrid)

    gvpd.DataBind(myNewSQLString)

    If ddlSearch.SelectedValue = "rollno" Then

    myNewSQLString =

    "SELECT TOP 1 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" _

    &

    "FROM TX_ROLL txroll LEFT OUTER JOIN TX_ROLL_ASSESS ON txroll.ROLL_NO = TX_ROLL_ASSESS.ROLL_NO" _

    &

    "WHERE txroll.ROLL_NO = @ROLL_NO" _

    &

    "ORDER BY TX_ROLL_ASSESS.ASS_YEAR DESC"

    'ElseIf ddlSearch.SelectedValue = "address" Then

    ' myNewSQLString = "USE this SQL SELECT for ADDRESS"

    'ElseIf ddlSearch.SelectedValue = "legal" Then

    ' myNewSQLString = "USE this SQL SELECT for LEGAL"

    End If

    Dim sqlds As SqlDataSource = TryCast(Page.FindControl("dsGrid"), SqlDataSource)

    sqlds.SelectCommand = myNewSQLString

    Dim rgpd As DataGrid = TryCast(Page.FindControl("RadGrid1"), DataGrid)

    rgpd.DataBind()

    End Sub


    Thanks again,
    Brett

  9. Richard
    Richard avatar
    60 posts
    Member since:
    Feb 2008

    Posted 28 Jul 2008 Link to this post

    Just remove this line from your code:

    gvpd.DataBind(myNewSQLString)

    Databind() doesn't take any arguments, and you bind later after setting the SelectCommand of your datasource to your new string... although you seem to be working with a different grid at that point.
  10. bslaght
    bslaght avatar
    184 posts
    Member since:
    Jun 2006

    Posted 29 Jul 2008 Link to this post

    Hi Richard, I tried what you said, but started getting an "Index out of Range" error.

    Still at square one.  I am posting my full code as it is right now, please disregard any of the above code or comments as I have made so many edits, this is only code of any relavance.

    I have no idea if I am performing the change of the sql select string at the right time or not. 

    Currently I am trying to set my SelectCommand on the SelectedIndexChanged of the drop down menu, how I don't know what should be happening on my button click other than a rebind of my grid.

    Any help still apprecaited....

    VB.net
    1   Protected Sub Page_Load(ByVal sender As ObjectByVal e As System.EventArgs) Handles Me.Load  
    2         imgPrint.Attributes.Add("onclick""javascript:window.print(); return false;")  
    3         lnkPrint.Attributes.Add("onclick""javascript:window.print(); return false;")  
    4     End Sub 
    5  
    6     Protected Sub RadGrid1_PreRender(ByVal sender As ObjectByVal e As System.EventArgs) Handles RadGrid1.PreRender  
    7         'change selection and add a response script to rebind the second grid  
    8         RadGrid1.Items(0).Selected = True 
    9         RadGrid2.MasterTableView.Rebind()  
    10     End Sub 
    11  
    12     Protected Sub btnSearch_Click(ByVal sender As ObjectByVal e As System.EventArgs) Handles btnSearch.Click  
    13         Dim rgpd As RadGrid = TryCast(Page.FindControl("RadGrid1"), RadGrid)  
    14         rgpd.MasterTableView.ClearSelectedItems()  
    15         rgpd.Rebind()  
    16     End Sub 
    17  
    18     Protected Sub ddlSearch_SelectedIndexChanged(ByVal sender As ObjectByVal e As System.EventArgs) Handles ddlSearch.SelectedIndexChanged  
    19         Dim myNewSQLString As String 
    20         myNewSQLString = "SELECT TOP 1 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" _  
    21                                 & "FROM TX_ROLL txroll LEFT OUTER JOIN TX_ROLL_ASSESS ON txroll.ROLL_NO = TX_ROLL_ASSESS.ROLL_NO" _  
    22                                 & "WHERE txroll.ROLL_NO = @ROLL_NO" _  
    23                                 & "ORDER BY TX_ROLL_ASSESS.ASS_YEAR DESC" 
    24  
    25         If ddlSearch.SelectedValue = "rollno" Then 
    26             myNewSQLString = "SELECT TOP 1 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" _  
    27                                 & "FROM TX_ROLL txroll LEFT OUTER JOIN TX_ROLL_ASSESS ON txroll.ROLL_NO = TX_ROLL_ASSESS.ROLL_NO" _  
    28                                 & "WHERE txroll.ROLL_NO = @ROLL_NO" _  
    29                                 & "ORDER BY TX_ROLL_ASSESS.ASS_YEAR DESC" 
    30  
    31         ElseIf ddlSearch.SelectedValue = "address" Then 
    32             myNewSQLString = "SELECT TOP 1 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" _  
    33                                 & "FROM TX_ROLL txroll LEFT OUTER JOIN TX_ROLL_ASSESS ON txroll.ROLL_NO = TX_ROLL_ASSESS.ROLL_NO" _  
    34                                 & "WHERE address = @ROLL_NO" _  
    35                                 & "ORDER BY TX_ROLL_ASSESS.ASS_YEAR DESC" 
    36  
    37         ElseIf ddlSearch.SelectedValue = "legal" Then 
    38             myNewSQLString = "SELECT TOP 1 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" _  
    39                                 & "FROM TX_ROLL txroll LEFT OUTER JOIN TX_ROLL_ASSESS ON txroll.ROLL_NO = TX_ROLL_ASSESS.ROLL_NO" _  
    40                                 & "WHERE txroll.ROLL_NO = @ROLL_NO" _  
    41                                 & "ORDER BY TX_ROLL_ASSESS.ASS_YEAR DESC" 
    42         End If 
    43  
    44         Dim sqlds As SqlDataSource = TryCast(Page.FindControl("dsGrid"), SqlDataSource)  
    45         sqlds.SelectCommand = myNewSQLString  
    46           
    47     End Sub 

    ASP.net
    1 <%@ Page Title="" Language="VB" MasterPageFile="~/MasterPage.master" AutoEventWireup="false" 
    2     CodeFile="details.aspx.vb" Inherits="test" %> 
    3  
    4 <%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %> 
    5 <%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %> 
    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         <asp:DropDownList ID="ddlSearch" runat="server" AutoPostBack="True" OnSelectedIndexChanged="ddlSearch_SelectedIndexChanged">  
    11             <asp:ListItem Value="rollno">Roll No.</asp:ListItem> 
    12             <asp:ListItem Value="address">Civic\St. Address</asp:ListItem> 
    13             <asp:ListItem Value="legal">Legal Derscription</asp:ListItem> 
    14         </asp:DropDownList> 
    15         <asp:TextBox ID="txtSearch" runat="server" va>401015084000000</asp:TextBox> 
    16         <asp:Button ID="btnSearch" runat="server" Text="Search" OnClick="btnSearch_Click" /> 
    17     </div> 
    18     <div class="tablehdr">  
    19         <h3> 
    20             Municipal Property Details</h3> 
    21     </div> 
    22     <telerik:RadGrid ID="RadGrid1" runat="server" DataSourceID="dsGrid" Skin="Telerik" 
    23         GridLines="None" OnPreRender="RadGrid1_PreRender">  
    24         <MasterTableView AutoGenerateColumns="False" DataSourceID="dsGrid" DataKeyNames="ROLL_NO">  
    25             <RowIndicatorColumn> 
    26                 <HeaderStyle Width="20px"></HeaderStyle> 
    27             </RowIndicatorColumn> 
    28             <ExpandCollapseColumn> 
    29                 <HeaderStyle Width="20px"></HeaderStyle> 
    30             </ExpandCollapseColumn> 
    31             <Columns> 
    32                 <telerik:GridBoundColumn DataField="ROLL_NO" HeaderText="Roll Number" SortExpression="ROLL_NO" 
    33                     UniqueName="ROLL_NO">  
    34                 </telerik:GridBoundColumn> 
    35                 <telerik:GridBoundColumn DataField="Address" HeaderText="Address" SortExpression="Address" 
    36                     UniqueName="Address" ReadOnly="True">  
    37                 </telerik:GridBoundColumn> 
    38                 <%--<telerik:GridBoundColumn DataField="LEGAL1" HeaderText="LEGAL1"   
    39             SortExpression="LEGAL1" UniqueName="LEGAL1">  
    40         </telerik:GridBoundColumn> 
    41         <telerik:GridBoundColumn DataField="LEGAL2" HeaderText="LEGAL2"   
    42             SortExpression="LEGAL2" UniqueName="LEGAL2">  
    43         </telerik:GridBoundColumn> 
    44         <telerik:GridBoundColumn DataField="LEGAL3" HeaderText="LEGAL3"   
    45             SortExpression="LEGAL3" UniqueName="LEGAL3">  
    46         </telerik:GridBoundColumn> 
    47         <telerik:GridBoundColumn DataField="LEGAL4" HeaderText="LEGAL4"   
    48             SortExpression="LEGAL4" UniqueName="LEGAL4">  
    49         </telerik:GridBoundColumn> 
    50         <telerik:GridBoundColumn DataField="LEGAL5" HeaderText="LEGAL5"   
    51             SortExpression="LEGAL5" UniqueName="LEGAL5">  
    52         </telerik:GridBoundColumn>--%> 
    53                 <telerik:GridTemplateColumn HeaderText="Legal Description" UniqueName="TemplateColumn">  
    54                     <ItemTemplate> 
    55                         <asp:Label ID="Label58" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.LEGAL1") %>'>  
    56                         </asp:Label><br /> 
    57                         <asp:Label ID="Label1" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.LEGAL2") %>'>  
    58                         </asp:Label><br /> 
    59                         <asp:Label ID="Label2" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.LEGAL3") %>'>  
    60                         </asp:Label><br /> 
    61                         <asp:Label ID="Label3" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.LEGAL4") %>'>  
    62                         </asp:Label><br /> 
    63                         <asp:Label ID="Label4" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.LEGAL5") %>'>  
    64                         </asp:Label> 
    65                     </ItemTemplate> 
    66                 </telerik:GridTemplateColumn> 
    67                 <telerik:GridBoundColumn DataField="CLASS" HeaderText="Class" SortExpression="CLASS" 
    68                     UniqueName="CLASS">  
    69                 </telerik:GridBoundColumn> 
    70                 <telerik:GridBoundColumn DataField="ASSESSMENT" DataType="System.Decimal" HeaderText="Assesed Value" 
    71                     SortExpression="ASSESSMENT" UniqueName="ASSESSMENT" DataFormatString="{0:c}">  
    72                 </telerik:GridBoundColumn> 
    73                 <telerik:GridHyperLinkColumn HeaderText="More Details" NavigateUrl="details.aspx?txtSearch={0}" 
    74                     Text="View Details" UniqueName="column">  
    75                     <HeaderStyle HorizontalAlign="Center" /> 
    76                     <ItemStyle HorizontalAlign="Center" /> 
    77                 </telerik:GridHyperLinkColumn> 
    78             </Columns> 
    79         </MasterTableView> 
    80         <FilterMenu EnableTheming="True">  
    81             <CollapseAnimation Type="OutQuint" Duration="200"></CollapseAnimation> 
    82         </FilterMenu> 
    83     </telerik:RadGrid> 
    84     <asp:SqlDataSource ID="dsGrid" runat="server" ConnectionString="<%$ ConnectionStrings:csProperty %>" 
    85         SelectCommand="SELECT TOP 1 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  
    86 FROM TX_ROLL txroll LEFT OUTER JOIN TX_ROLL_ASSESS ON txroll.ROLL_NO = TX_ROLL_ASSESS.ROLL_NO    
    87 WHERE txroll.ROLL_NO = @ROLL_NO  
    88 ORDER BY TX_ROLL_ASSESS.ASS_YEAR DESC"> 
    89         <SelectParameters> 
    90             <asp:ControlParameter Name="ROLL_NO" ControlID="txtSearch" Type="String" /> 
    91             <%--<asp:QueryStringParameter Name="ROLL_NO" QueryStringField="txtSearch" Type="String" />--%> 
    92         </SelectParameters> 
    93     </asp:SqlDataSource> 
    94     <br /> 
    95     <asp:Panel ID="pnlStructure" runat="server">  
    96         <div class="tablehdr">  
    97             <h3> 
    98                 Sturcture Details</h3> 
    99         </div> 
    100         <telerik:RadGrid ID="RadGrid2" runat="server" DataSourceID="dsStructure" GridLines="None" 
    101             Skin="Telerik">  
    102             <MasterTableView AutoGenerateColumns="False" DataSourceID="dsStructure" DataKeyNames="ROLL_NO">  
    103                 <RowIndicatorColumn> 
    104                     <HeaderStyle Width="20px" /> 
    105                 </RowIndicatorColumn> 
    106                 <ExpandCollapseColumn> 
    107                     <HeaderStyle Width="20px" /> 
    108                 </ExpandCollapseColumn> 
    109                 <Columns> 
    110                     <telerik:GridTemplateColumn UniqueName="TemplateColumn1" HeaderText="Construction">  
    111                         <ItemTemplate> 
    112                             CHAR OF CONST:<asp:Label ID="Label58" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.CHAR_OF_CONST") %>'>  
    113                             </asp:Label><br /> 
    114                             QUALITY:<asp:Label ID="Label1" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.QUALITY") %>'>  
    115                             </asp:Label><br /> 
    116                             SHAPE:<asp:Label ID="Label2" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.SHAPE") %>'>  
    117                             </asp:Label><br /> 
    118                             YEAR BUILT:<asp:Label ID="Label3" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.YEAR_BUILT") %>'>  
    119                             </asp:Label><br /> 
    120                             YEAR BUILT CODE:<asp:Label ID="Label4" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.YEAR_BUILT_CODE") %>'>  
    121                             </asp:Label></ItemTemplate>  
    122                     </telerik:GridTemplateColumn> 
    123                     <telerik:GridTemplateColumn UniqueName="TemplateColumn2" HeaderText="Building">  
    124                         <ItemTemplate> 
    125                             CONDITION:<asp:Label ID="Label59" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.CONDITION") %>'>  
    126                             </asp:Label><br /> 
    127                             FULL STORYS:<asp:Label ID="Label1" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.FULL_STOREYS") %>'>  
    128                             </asp:Label><br /> 
    129                             PART STORYS:<asp:Label ID="Label2" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.PART_STOREYS") %>'>  
    130                             </asp:Label><br /> 
    131                             HEIGHT EFF DATE:<asp:Label ID="Label3" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.HEIGHT_EFF_DATE_S") %>'>  
    132                             </asp:Label><br /> 
    133                             SPLIT:<asp:Label ID="Label4" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.SPLIT") %>'>  
    134                             </asp:Label></ItemTemplate>  
    135                     </telerik:GridTemplateColumn> 
    136                     <telerik:GridTemplateColumn UniqueName="TemplateColumn3" HeaderText="Area">  
    137                         <ItemTemplate> 
    138                             GROSS AREA:<asp:Label ID="Label59" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.GROSS_AREA") %>'>  
    139                             </asp:Label><br /> 
    140                             TOTAL BASEMENT:<asp:Label ID="Label1" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.TOTAL_BASEMENT") %>'>  
    141                             </asp:Label><br /> 
    142                             FINISH BASEMENT:<asp:Label ID="Label2" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.FINISH_BASEMENT") %>'>  
    143                             </asp:Label><br /> 
    144                             FINISH BASEMENT:<asp:Label ID="Label3" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.FINISH_BASEMENT_TY") %>'>  
    145                             </asp:Label><br /> 
    146                             </asp:Label></ItemTemplate>  
    147                     </telerik:GridTemplateColumn> 
    148                     <telerik:GridTemplateColumn UniqueName="TemplateColumn4" HeaderText="Features">  
    149                         <ItemTemplate> 
    150                             FULL BATHS:<asp:Label ID="Label59" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.FULL_BATHS") %>'>  
    151                             </asp:Label><br /> 
    152                             HALF BATHS:<asp:Label ID="Label1" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.HALF_BATHS") %>'>  
    153                             </asp:Label><br /> 
    154                             # BEDROOMS:<asp:Label ID="Label2" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.NO_OF_BEDROOMS") %>'>  
    155                             </asp:Label><br /> 
    156                             # FIREPLACES:<asp:Label ID="Label3" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.NO_OF_FIREPLACES") %>'>  
    157                             </asp:Label><br /> 
    158                             HEATING TYPE:<asp:Label ID="Label5" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.HEATING_TYPE") %>'>  
    159                             </asp:Label><br /> 
    160                             AIR CONDITIONING:<asp:Label ID="Label6" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.AIR_CONDITIONING") %>'>  
    161                             </asp:Label><br /> 
    162                             </asp:Label></ItemTemplate>  
    163                     </telerik:GridTemplateColumn> 
    164                     <telerik:GridTemplateColumn UniqueName="TemplateColumn" HeaderText="Garage">  
    165                         <ItemTemplate> 
    166                             GARAGE TYPE:<asp:Label ID="Label59" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.GARAGE_TYPE") %>'>  
    167                             </asp:Label><br /> 
    168                             GARAGE SPACES:<asp:Label ID="Label1" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.GARAGE_SPACES") %>'>  
    169                             </asp:Label><br /> 
    170                             STRUCTURE CODE:<asp:Label ID="Label2" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.STRUCT_CODE") %>'>  
    171                             </asp:Label></ItemTemplate>  
    172                     </telerik:GridTemplateColumn> 
    173                 </Columns> 
    174             </MasterTableView> 
    175             <FilterMenu EnableTheming="True">  
    176                 <CollapseAnimation Duration="200" Type="OutQuint" /> 
    177             </FilterMenu> 
    178         </telerik:RadGrid><cc1:CollapsiblePanelExtender ID="cpe" runat="Server" TargetControlID="pnlStructure" 
    179             CollapsedSize="0" Collapsed="True" ExpandControlID="RadGrid1" CollapseControlID="RadGrid1" 
    180             AutoCollapse="False" AutoExpand="False" ScrollContents="False" ImageControlID="imgLegal" 
    181             ExpandedImage="~/lib/img/collapse.jpg" CollapsedImage="~/lib/img/expand.jpg" 
    182             ExpandDirection="Vertical" SuppressPostBack="true" /> 
    183         </cc1:CollapsiblePanelExtender><asp:ImageButton ID="imgPrint" runat="server" ImageUrl="lib/img/printer.png" 
    184             ImageAlign="Middle" AutoPostBack="False" CausesValidation="False" CssClass="imgPrint" /><asp:LinkButton  
    185                 ID="lnkPrint" runat="server" CssClass="lnkPrint">Print Now</asp:LinkButton> 
    186         <asp:SqlDataSource ID="dsStructure" runat="server" ConnectionString="<%$ ConnectionStrings:csProperty %>" 
    187             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">  
    188             <SelectParameters> 
    189                 <asp:ControlParameter ControlID="RadGrid1" Name="ROLL_NO" PropertyName="SelectedValue" 
    190                     Type="string" /> 
    191             </SelectParameters> 
    192         </asp:SqlDataSource> 
    193     </asp:Panel> 
    194 </asp:Content> 

    Thanks again,
    Brett
  11. Richard
    Richard avatar
    60 posts
    Member since:
    Feb 2008

    Posted 29 Jul 2008 Link to this post

    Hi Brett,

    Try just rebinding your grid at the end of your SelectedIndexChanged code.  It won't work in the button click as the change to your SelectCommand won't be persisted between round trips to the server.  If you need to use the button to rebind then you will have to set the SelectCommand in the Button_Click event.
  12. bslaght
    bslaght avatar
    184 posts
    Member since:
    Jun 2006

    Posted 29 Jul 2008 Link to this post

    Tried doing the rebind at the end of teh selectedindexchanged event, and I get "Object reference not set to an instance of an object. "

    Line 51:         Dim sqlds As SqlDataSource = TryCast(Page.FindControl("dsGrid"), SqlDataSource)
    Line 52:         sqlds.SelectCommand = myNewSQLString


    Any more thoughts?  Thanks again.
  13. Richard
    Richard avatar
    60 posts
    Member since:
    Feb 2008

    Posted 29 Jul 2008 Link to this post

    Your code is not finding your datasource control.  If you are not using the master page scenario then use Page.Form.FindControl("dsGrid") instead of just Page.FindControl("dsGrid").  If you are using the master page scenario then use Page.Form.FindControl("ContentPlaceholderID").FindControl("dsGrid")
  14. bslaght
    bslaght avatar
    184 posts
    Member since:
    Jun 2006

    Posted 29 Jul 2008 Link to this post

    Hi Richard,
     I updated my code to find the dsGrid, and that seems to work, but only when searching for Roll_no, if I change the dropdown to "Address" the page refreshes, but I get
    "System.Data.SqlClient.SqlException: Line 1: Incorrect syntax near 'txroll'."

    Same thing happens If I change dropdown to "Legal"

    Any thoughts on this.  I am getting so confused...seems like nothing is working as I think it should.

    Also when the page first loads..how to do I stop the grid from rendering and throwing an error since nohting has been search yet, it has nothing to bind to?

    Thanks
    Brett
  15. Richard
    Richard avatar
    60 posts
    Member since:
    Feb 2008

    Posted 29 Jul 2008 Link to this post

    For the page load I would suggest setting the initial SelectCommand of your datasource to a SQL statement that does not return any records.

    For the other problem you will need to examine your SQL statements.  When you get the error look in the error details and you should be able to find the SQL that was actually executed.  You can check it for syntax, or copy it and test it directly in your database and maybe get more details on why it failed.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017