2011-01-21 82 views
0

我有一個奇怪的問題。我在這裏(http://www.4guysfromrolla.com/articles/071107-1.aspx),隨後的例子來顯示一個ajax彈出,但它不能正常工作。阿賈克斯Popupcontrolextender發出

我的問題是圖像屬性設置不正確,我使用Firebug檢查,這是我得到的第1頁加載後。

<img src="StyleSheets/magglass.jpg" id="mainContent_TheGrid_MagGlass_0"> 

現在奇怪的,如果我去第2頁,正確設置所有圖像的onmouseover事件,如果我回來第1頁,它被正確設置過,例如

<img src="StyleSheets/magglass.jpg" onmouseover="$find('pce0').showPopup(); " id="mainContent_TheGrid_MagGlass_0"> 

我通過代碼加強並證實rowcreated事件被解僱了我的網格,每一行

什麼想法?

我的代碼的例子略有不同,見下文

protected void TheGrid_RowCreated(object sender, GridViewRowEventArgs e) 
{ 
    if (e.Row.RowType == DataControlRowType.DataRow) 
    { 
     // Programmatically reference the PopupControlExtender 
     PopupControlExtender pce = e.Row.FindControl("TheGrid_PopupControlExtender") as PopupControlExtender; 

     // Set the BehaviorID 
     string behaviorID = string.Concat("pce", e.Row.RowIndex); 
     pce.BehaviorID = behaviorID; 

     // Programmatically reference the Image control 
     Image i = (Image)e.Row.Cells[0].FindControl("MagGlass"); 

     // Add the client-side attributes (onmouseover & onmouseout) 
     string OnMouseOverScript = string.Format("$find('{0}').showPopup(); ", behaviorID); 


     i.Attributes.Add("onmouseover", OnMouseOverScript); 

    } 
} 

的GetDynamicContent方法如下,它增加了hidepopup方法。

[System.Web.Services.WebMethodAttribute(), System.Web.Script.Services.ScriptMethodAttribute()] 
public static string GetDynamicContent(string contextKey) 
{ 

    GridView MyGrid = (GridView)HttpContext.Current.Session["TheGrid"]; 

    var MyVar = from GridViewRow MyRow in MyGrid.Rows 
       where MyRow.Cells[MyRow.Cells.Count - 1].Text == contextKey 
       select MyRow; 

    //This is the selected row by the user 
    GridViewRow MyGridRow = MyVar.SingleOrDefault(); 

    //MyGridRow.Cells[3].Text is the log entry. 
    string MyTable = @"<table class=""PopUpTable""><tr><td><textarea class=""textarea"">" 
     + MyGridRow.Cells[3].Text + "</textarea></td>"; 

    //MyGridRow.RowIndex is used to determine the name of popup control for the hidepopup script 
    MyTable += "<td><button type=\"button\" class=\"PopUpButton\" onclick=\"$find('pce" + MyGridRow.RowIndex.ToString() + "').hidePopup();\">Close</button></td></tr></table>"; 

    return MyTable; 

} 

這是PageIndexChanging事件

protected void TheGrid_PageIndexChanging(object sender, GridViewPageEventArgs e) 
{ 

    TheGrid.PageIndex = e.NewPageIndex;  

     LoadFromDB(); 

} 

的LoadFromDB方法在這裏:

private void LoadFromDB() 
{ 
    try 
    { 
     LOGDBDataContext LDC = new LOGDBDataContext(ConfigurationManager.ConnectionStrings[Constants.ConnectionStringName].ConnectionString); 



     string Query = @"DateTimeStamp >= @0 and DateTimeStamp <= @1"; 


     var Tolo = LDC 
        .Logs 
        .Where(Query, this.FromCalendar.SelectedDate, this.ToCalendar.SelectedDate) 
        .OrderBy("DateTimeStamp desc") 
        .Select("new (LogID, DateTimeStamp, Organization, LogEntry, ServerHostname)"); 


     TheGrid.DataSource = Tolo; 
     TheGrid.DataBind(); 



    } 


    catch (Exception ex) 
    { 
    //do something here 
    } 
} 

回答

0

沒關係,找到了答案。

  1. 可憐的調試
  2. 在 一個可憐的嘗試結算,這不是 由pagechanging事件

無能調用你的名字是yomismo

在GridView