2011-08-11 51 views
1

我有一個過濾用一個下拉框一個gridview。 GridView有LinkBut​​tons,它們調用ModalPopUpExtender來顯示數據。一旦GridView被過濾並且單擊LinkBut​​ton,GridView過濾結果就會改變,數據也不正確。GridView的篩選結果更改ModalPopUpExtender調用後

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

    } 
+0

是這樣的WinForms或asp.net web表單?你需要更具體的 – Martin

+0

這是一個asp.net的網頁表單 – Kianna

+0

請標記您的問題,所以它變得更加具體 – Martin

回答

1

我解決這個問題的辦法是通過保存FilterExpression在會話變量並在Page_Load中分配給它,因爲我每次點擊一個LinkBut​​ton它重新加載時間這一頁。

感謝您的幫助。

1

頁面生命週期的哪一步發生?從這個小片段中知道發生了什麼很難。需要更多的上下文。

您是否嘗試過包裝的下拉與此過濾:

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

我試着用包裝過濾if語句和GridView控件選擇了下拉時不過濾的。還有更多的代碼被添加到問題中。謝謝。 – Kianna