c# asp.net sorting gridview

c#GridView Refresh Index después de aplicar el filtro



asp.net sorting (0)

Hola, tengo una vista de cuadrícula y algunos cuadros de texto que los usuarios pueden filtrar la vista de cuadrícula mediante un botón de búsqueda.

Tengo problemas para actualizar el hipervínculo Seleccionar índice en la vista de cuadrícula después de aplicar un filtro.

ver el código del botón a continuación.

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

¿Cómo actualizo el índice detrás del hipervínculo de selección?

incluso cuando ordeno una columna, el hipervínculo de selección no muestra la identificación correcta que estoy esperando.

ver el código fuente de Gridview a continuación.

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

y también mi evento GridView1_PageIndexChanging a continuación

protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e) { GridView1.PageIndex = e.NewPageIndex; DataBind(); }

Saludos

Robar