tags:

views:

14

answers:

0

Hi,

I have created two hidden fields in my Gridview control per the code below:

<asp:SearchGridView ID="MySearch" runat="server" 
        DataSourceID="EntityDataSource1" ShowFooter="True">
        <SearchFilter>
            <asp:ListItem Value="PartName">Part Name</asp:ListItem>
            <asp:ListItem>NSN</asp:ListItem>
        </SearchFilter>

        <Columns>
            <asp:TemplateField Visible="False" >
            <ItemTemplate>
                <asp:HiddenField runat="server" ID="hfSearchText" />
            </ItemTemplate>
            <ItemTemplate>
                <asp:HiddenField runat="server" ID="hfSort" />
            </ItemTemplate>
            </asp:TemplateField>
       </Columns>

    </asp:SearchGridView> 

In my codebehind file, I need to reference hfSearchText and hfSort. I've attempted this as follows:

Protected Sub MySearch_SearchGrid(ByVal _strSearch As String)
    hfSearchText.Value = _strSearch
    BindData()
End Sub

Protected Sub MySearch_Sorting(ByVal sender As Object, ByVal e As GridViewSortEventArgs)
    'If hfSort has the same value as before,
    ' the sorting should be done in descending order
    If hfSort.Value = e.SortExpression Then
        hfSort.Value = e.SortExpression & " Desc"
    Else
        hfSort.Value = e.SortExpression
    End If
    BindData()
End Sub

Unfortunately, I receive errors stating hfSearchText and hfSort have not been declared. What is the proper way of declaring these 2 hidden gridview fields?

Thanks, Sid