c# - sqldatasource更新 - sqldatasource參數來源



c#GridView刷新索引後應用過濾器 (0)

你好,我有一個gridview和幾個文本框,用戶可以通過搜索按鈕篩選gridview。

在應用篩選器後,在刷新GridView中的選擇索引超鏈接時遇到問題。

看下面的按鈕代碼。

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();

    }

如何刷新選定超鏈接後面的索引。

即使當我排序列時選擇超鏈接不顯示正確的ID我期待。

請參閱下面的Gridview源代碼。

<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>

以及我的GridView1_PageIndexChanging事件下面

protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {


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

    }

問候