2012-04-09 55 views
0

我有一個gridview在頁面加載我通過使用checkfunction更改按鈕的一些圖像但是,當我更改頁面的索引。頁面加載不我試過 GridView1_PageIndexChanging,GridView1_SelectedIndexChanged程序被調用,GridView1_PageIndexChanged事件如何在頁面更改時填充datagridview中的某些列? c#

在代碼在頁面加載,我複製它的事件,但它不工作

 DBConnection db = new DBConnection(); 


     for (int i = 0; i < GridView1.Rows.Count; i++) 
     { 
      GridViewRow gvrow = GridView1.Rows[i]; 
      ImageButton ib = (ImageButton)gvrow.Controls[1].Controls[0]; 

      string feedUrl = ((HiddenField)GridView1.Rows[i].FindControl("HiddenField1")).Value; 



      bool res = db.CheckAddedFeeds(feedUrl, User_Name); 
      if (res) 
      { 
       ib.ImageUrl = "~/images/delete.png"; 
      } 

     } 
+0

,你必須在這些事件再次綁定的GridView。 – 2012-04-09 10:15:29

回答

0

首先所有你需要的綁定的GridView如下

private void BindGridView() 
{ 
     // place your bind grid code here.. 
    DBConnection db = new DBConnection(); 

    for (int i = 0; i < GridView1.Rows.Count; i++) 
    { 
     GridViewRow gvrow = GridView1.Rows[i]; 
     ImageButton ib = (ImageButton)gvrow.Controls[1].Controls[0]; 

     string feedUrl = ((HiddenField)GridView1.Rows[i].FindControl("HiddenField1")).Value; 



     bool res = db.CheckAddedFeeds(feedUrl, User_Name); 
     if (res) 
     { 
      ib.ImageUrl = "~/images/delete.png"; 
     } 

    } 


} 

調用這個函數在你的心尖代碼創建一個函數後面的頁面加載

protected void Page_Load(object sender, EventArgs e) 
{ 
    if (!Page.IsPostBack) 
    { 
     BindGridView(); 
    } 

} 

代碼處理分頁事件背後像下面

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

希望這將幫助你...

+0

它不能解決問題 – leventkalay92 2012-04-09 11:04:40

相關問題