开发者

Gridview Filter Results Change After ModalPopUpExtender Called

I have a gridview that is filtered with a dropdown box. The gridview has LinkButtons that call a ModalPopUpExtender to display data. Once the gridview is filtered and a LinkButton is clicked the GridView filtered results change and the data is incorrect.

<asp:DropDownList ID="ddl_temp" runat="server" AutoPostBack="True" 
                    onselectedindexchanged="ddl_temp_SelectedIndexChanged">
                    <asp:ListItem>Select Status</asp:ListItem>
                    <asp:ListItem>Open</asp:ListItem>
                    <asp:ListItem>Closed</asp:ListItem>
                </asp:DropDownList>
protected void tabs()
{
....
sds.FilterParameters.Clear();
        sds.SelectParameters.Clear();
        ControlParameter cp = new ControlParameter();
            cp.ControlID = ddl_temp.ID.ToString();
            cp.PropertyName = "SelectedValue";
            cp.Name = "Status";
            cp.Type = TypeCode.String;
            cp.ConvertEmptyStringToNull = false;
            sds.FilterParameters.Add(cp);           
            sds.ID = "sds1";
            sds.SelectParameters.Add("sid", sid);
            IssuesPanel.Controls.Add(sds);

        BoundField date = new BoundField();
            date.HeaderText = "Date";
            date.DataField = dt.Columns[2].ToString();
            date.SortExpression = dt.Columns[2].ToString();

        BoundColumn bc = new BoundColumn();
        bc.DataField = dt.Columns[2].ToString();

        BoundField status = new BoundField();
            status.HeaderText = "Status";
            status.DataField = dt.Columns[3].ToString();

         gv4 = new GridView();
            gv4.DataSource = sds;
            gv4.RowDataBound += gv4_RowCommand;
            gv4.Columns.Add(date);
            gv4.Columns.Add(status);
            gv4.CellPadding = 6;
            gv4.AutoGenerateColumns = false;
            //gv4.AllowSorting = true;
            gv4.AllowPaging = true;
            gv4.DataBind();             
        IssuesPanel.Controls.Add(gv4);
...
}



protected void gv4_RowCommand(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            LinkButton lb = new LinkButton();
            lb.Text = Convert.ToString(DataBinder.Eval(e.Row.DataItem, "Title"));
            lb.ID = Convert.ToString(DataBinder.Eval(e.Row.DataItem, "Issue_ID"));
            lb.Click += new EventHandler(issueModal);
       开发者_如何转开发     e.Row.Cells[0].Controls.Add(lb);

        }

    }

protected void ddl_temp_SelectedIndexChanged(object sender, EventArgs e)
    {


            sds.FilterParameters.Clear();
            ControlParameter cp = new ControlParameter();
            cp.ControlID = ddl_temp.ID.ToString();
            cp.PropertyName = "SelectedValue";
            cp.Name = "Status";
            cp.Type = TypeCode.String;
            cp.ConvertEmptyStringToNull = false;
            sds.FilterParameters.Add(cp);
            sds.FilterExpression = "Status='{0}'";
                gv4.DataSource = sds;
                gv4.DataBind();

    }


At what step of the page lifecycle is this happening? It's kind of tough to tell what's going on from that small snippet. Need a little more context.

Have you tried wrapping your dropdown filtering with this:

if (!Page.IsPostBack)
{
    //dropdown filtering here
}


The way I solved this issue was by saving the FilterExpression in a session variable and assigning it on page_load since every time I clicked a LinkButton it reloaded the page.

Thanks for your help.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜