Question

I have encountered puzzling exception while trying to implement string search function to point out users' searched grid rows. Here's a snippet of the code I am employing, previously this piece of code has worked flawlessly with griddatabound columns and it is now throwing No property or field 'ObjSN' exists in type 'DataRowView' at me.

ASPX

<telerik:RadComboBox ID="rcbFieldName" runat="server" Label="Pencarian: " LabelCssClass="filterLabel">
    <Items>
        <telerik:RadComboBoxItem Text="Container No." Value="ObjSN" />
        <telerik:RadComboBoxItem Text="Seal No." Value="TrxSeal" />                                      
    </Items>
</telerik:RadComboBox>
<telerik:RadTextBox ID="txtSearch" runat="server" OnTextChanged="txtSearch_TextChanged" />
<telerik:RadButton ID="btnSearchGrid" runat="server" Text="Search" ToolTip="Search Record" />
<telerik:RadButton ID="btnShowAllItem" runat="server" Text="Reset" ToolTip="Reset View" OnClick="btnShowAll_Click" />

<telerik:RadGrid ID="RadGrid1" 
    GridLines="None" 
    AutoGenerateColumns="false" 
    PageSize="10"
    AllowPaging="true" 
    AllowSorting="true" 
    runat="server" 
    DataSourceID="MasterViewDataSource" 
    OnItemDataBound="OnItemDataBoundHandler" 
    OnItemCommand="RadGrid1_ItemCommand"
    AllowAutomaticInserts="True" 
    AllowAutomaticDeletes="True"
    ShowStatusBar="true">
    <PagerStyle Mode="NextPrevAndNumeric" />
        <MasterTableView ShowFooter="false" DataKeyNames="TrxId" EditMode="InPlace" CommandItemDisplay="TopAndBottom">
            <Columns>
                <telerik:GridBoundColumn DataField="TrxId" HeaderText="Trx No." ReadOnly="true" DataFormatString="{0:0000}" UniqueName="TrxId"/>

                    <telerik:GridTemplateColumn UniqueName="ObjId" HeaderText="Container No."
                        SortExpression="ObjSN">
                        <FooterTemplate>Template footer</FooterTemplate>
                        <FooterStyle VerticalAlign="Middle" HorizontalAlign="Center" />
                            <ItemTemplate>
                                <%#DataBinder.Eval(Container.DataItem, "ObjSN")%>
                            </ItemTemplate>

                        <EditItemTemplate>
                            <telerik:RadComboBox runat="server" ID="RadComboBox1" EnableLoadOnDemand="True" DataTextField="ObjSN" 
                                OnItemsRequested="RadComboBox1_ItemsRequested" OnSelectedIndexChanged="RadComboBox1_SelectedIndexChanged" 
                                DataValueField="ObjId" AutoPostBack="true" HighlightTemplatedItems="true" Height="140px" Width="220px" 
                                DropDownWidth="300px">
                                    <HeaderTemplate>
                                        <ul>
                                            <li class="col1">Container No.</li>
                                            <li class="col2">Container Type</li>
                                       </ul>
                                    </HeaderTemplate>

                                    <ItemTemplate>
                                        <ul>
                                            <li class="col1">
                                                <%# DataBinder.Eval(Container, "Text")%>
                                            </li>
                                            <li class="col2">
                                                <%# DataBinder.Eval(Container, "Attributes['ObjType']")%>
                                            </li>
                                       </ul>
                                  </ItemTemplate>
                             </telerik:RadComboBox>
                        </EditItemTemplate>
                   </telerik:GridTemplateColumn>
             </Columns>
         </MasterTableView>
    </telerik:RadGrid>
<asp:SqlDataSource ID="MasterViewDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:ZEUS %>"
     SelectCommand="SELECT TransactsData.TrxId,TransactsData.ObjId, 
                           ObjectsData.ObjSN, ObjectsData.ObjType  

                    FROM   TransactsData INNER JOIN              
                           ObjectsData ON TransactsData.ObjId = ObjectsData.ObjId" />

C#

protected void txtSearch_TextChanged(object sender, EventArgs e)
    {
        RadTextBox txt = sender as RadTextBox;
        RadComboBox list = (RadComboBox)((txt.NamingContainer).FindControl("rcbFieldName"));

        string option;
        if (list.SelectedValue == "TrxId")
            {
                option = " = ";
            }
            else
            {
                option = " LIKE ";
            }

        string filterExpression;

        if (option == " = ")
            {
                filterExpression = "(" + list.SelectedValue + option + txt.Text + ")";
            }
            else
            {
                filterExpression = "(" + list.SelectedValue + option + "'%" + txt.Text + "%'" + ")";
            }

        RadGrid1.MasterTableView.FilterExpression = filterExpression;
        RadGrid1.MasterTableView.Rebind();
        RadAjaxManager1.FocusControl(txtSearch.ID);
    }

    protected void btnShowAll_Click(object sender, EventArgs e)
    {
        RadGrid1.MasterTableView.FilterExpression = "";
        RadGrid1.MasterTableView.Rebind();
        txtSearch.Text = string.Empty;
        RadAjaxManager1.FocusControl(txtSearch.ID);
    }

thanks in advance.

Was it helpful?

Solution

It Seems that I forgot to set the EnableLinqExpressions to False, thus causing deformed SQL Query. Anyhow this method only works for gridboundcolumns and does not apply to template columns.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top