c#GridView Aggiorna indice dopo aver applicato il filtro



asp.net sorting (0)

Ciao, ho una griglia e alcune caselle di testo che gli utenti possono filtrare il gridview tramite un pulsante di ricerca.

Ho problemi a aggiornare il collegamento ipertestuale Select Index all'interno di gridview dopo l'applicazione di un filtro.

vedere il codice del pulsante qui sotto.

protected void PropSearch_Search_Click(object sender, EventArgs e)
    {

        bool Others = false;

        String Horizon_PropID = "";
        String Horizon_SiteID = "";
        String Zone = "";
        String PropName = "";
        String SiteName = "";
        String PostCode = "";
        String Town = "";


        String Where = "";
        String SqlWhere = "";

        Horizon_PropID = PropSearch_HorizonPropID.Text;
        Horizon_SiteID = PropSearch_HorizonSiteID.Text;
        Zone = PropSearch_Zone.Text;
        PropName = PropSearch_PropName.Text;
        SiteName = PropSearch_SiteName.Text;
        PostCode = PropSearch_PostCode.Text;
        Town = PropSearch_Town.Text;


        BindingSource BS = new BindingSource();
        BS.DataSource = GridView1.DataSource;
        BS.Filter = "";





        if (Horizon_PropID != "")
                {
                    Where = "Horizon_Property_ID like '%" + Horizon_PropID + "%' ";

            SqlWhere = "Horizon_Property_ID like %'" + Horizon_PropID + "'% ";

                    Others = true;
                }


        //////////////////////////////////////////////////////////////////////////////////////////////

        if (Horizon_SiteID != "" && Others == true)

        {
            Where = Where + " and Horizon_Site_Id like '%" + Horizon_SiteID + "%' ";

        }

        else if (Horizon_SiteID != "" && Others == false)

        {
            Where = "Horizon_Site_Id like '%" + Horizon_SiteID + "%' ";
            Others = true;
        }



        //////////////////////////////////////////////////////////////////////////////////////////////////////


        if (PropName != "" && Others == true)

        {
            Where = Where + " and Property_Name like '%" + PropName + "%' ";


        }

        else if (PropName != "" && Others == false)

        {
            Where = "Property_Name like '%" + PropName + "%' ";
            Others = true;
        }


        //////////////////////////////////////////////////////////////////////////////////////////////////////


        if (SiteName != "" && Others == true)

        {
            Where = Where + " and Site_Name like '%" + SiteName + "%' ";

        }

        else if (SiteName != "" && Others == false)

        {

            Where = "Site_Name like '%" + SiteName + "%' ";
            Others = true;
        }

        //////////////////////////////////////////////////////////////////////////////////////////////////////


        if (PostCode != "" && Others == true)

        {
            Where = Where + " and PostCode like '%" + PostCode + "%' ";


        }

        else if (PostCode != "" && Others == false)

        {
            Where = "PostCode like '%" + PostCode + "%' ";
            Others = true;

        }

        ////////////////////////////////////////////////////////////////////////////////////////////////////

        if (Town != "" && Others == true)

        {
            Where = Where + " and Town like '%" + Town + "%' ";


        }

        else if (Town != "" && Others == false)

        {
            Where = "Town like '%" + Town + "%' ";
            Others = true;

        }

        ////////////////////////////////////////////////////////////////////////////////////////////////////

        if (Zone == "All" && Others == false)

        {
            //Where = Where + " and Zone = " + "'"+Zone+"' ";
            Others = true;

        }

        else if (Zone != "All" && Others == false)

        {
            Where = " Zone = " + "'" + Zone + "' ";
            Others = true;
        }

        else if (Zone != "All" && Others == true)

        {
            Where = Where + " and Zone = " + "'" + Zone + "' ";

        }



        //txt_DS.Text = Where.ToString();

        BS.Filter = Where;

        Filtering = Where;


        GridView1.DataSource = BS.DataSource;   

        GridView1.DataBind();

    }

Come faccio ad aggiornare l'indice dietro il collegamento ipertestuale selezionato.

anche quando ordino una colonna il collegamento ipertestuale selezionato non mostra l'ID corretto che mi aspetto.

vedi il codice sorgente di Gridview di seguito.

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false"  Height ="1px" Width ="300px" OnSelectedIndexChanged="GridView1_SelectedIndexChanged" OnRowDataBound="GridView1_RowDataBound" OnPageIndexChanging="GridView1_PageIndexChanging" OnSorting="GridView1_Sorting" AutoGenerateSelectButton="True" AllowPaging="true" AllowSorting="True" >
            <Columns>






                <asp:BoundField DataField="Horizon_Property_Id" ReadOnly="True" HeaderText="Horizon_Property_Id" SortExpression="Horizon_Property_Id" />
                <asp:BoundField DataField="Horizon_Site_Id" ReadOnly="True" HeaderText="Horizon_Site_Id"  SortExpression="Horizon_Site_Id" />
                <asp:BoundField DataField="Zone" HeaderText="Zone" ReadOnly="True" SortExpression="Zone" />
                <asp:BoundField DataField="Property_Name" HeaderText="Property_Name" ReadOnly="True"  SortExpression="Property_Name"    />
                <asp:BoundField DataField="Site_Name" HeaderText="Site_Name" ReadOnly="True" SortExpression="Site_Name" />
                <asp:BoundField DataField="Street" HeaderText="Street" ReadOnly="True"  SortExpression="Street"    />
                <asp:BoundField DataField="Town" HeaderText="Town" ReadOnly="True" SortExpression="Town" />
                <asp:BoundField DataField="PostCode" HeaderText="PostCode" ReadOnly="True" SortExpression="PostCode" />





            </Columns>
        </asp:GridView>

e anche il mio evento GridView1_PageIndexChanging di seguito

protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {


        GridView1.PageIndex = e.NewPageIndex;
        DataBind();

    }

Saluti

rapinare