0

I have a bizarre problem. I have followed the example here (http://www.4guysfromrolla.com/articles/071107-1.aspx) to display an ajax popup, but it is not working properly.

The problem I have is that the image attributes are not set properly, I checked with Firebug and this is what I get on page 1 after load.

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

Now the bizarre, if I go to page 2, the onmouseover event is set properly for all images and if I come back to page 1, it is set properly too, e.g.

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

I stepped through the code and confirmed that the rowcreated event is firing for my grid, for each row

Any Ideas?

My code is slightly different to the example, see below

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

    }
}

The GetDynamicContent Method is below, which adds the hidepopup method.

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

}

This is the pageIndexChanging event

  protected void TheGrid_PageIndexChanging(object sender, GridViewPageEventArgs e)
{

    TheGrid.PageIndex = e.NewPageIndex;      

        LoadFromDB();

}

The LoadFromDB method here:

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
    }
}
yomismo
  • 103
  • 2
  • 8

1 Answers1

0

Never Mind, found the answer.

  1. Poor Debugging
  2. A poor attempt at clearing the gridview that was not invoked by the pagechanging event

Incompetence thy name is yomismo

yomismo
  • 103
  • 2
  • 8