Click here to Skip to main content
15,889,877 members
Please Sign up or sign in to vote.
5.00/5 (2 votes)
See more:
Hi,

I have found this link and used it as described however, i haven't been able to get the popup window working.

The link is:

http://www.ezzylearning.com/tutorial.aspx?tid=2861497[^]

Please see why it is not working and also if someone can find me another solution.

My code is:

using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Sales_DAL;
using Sales_BOL;
using AjaxControlToolkit;
using System.Text;

public partial class MCTX_Internal_SuperAdmin_frmShowDailyOutput : System.Web.UI.Page
{
    Dlayer dl = new Dlayer();
    _DailyOutput objDO = new _DailyOutput();
    _ShowDailyOutput bl = new _ShowDailyOutput();
    DataTable dt_Grid = new DataTable();
    string userid;

    protected void Page_Load(object sender, EventArgs e)
    {

        if (!IsPostBack)
        {
            GetEmpName();
            DataTable dtUserID = new DataTable();
            dtUserID = bl.selectuserid();
            ddlEmployees.DataSource = dtUserID;
            ddlEmployees.DataTextField = "user_id";
            ddlEmployees.DataBind();
            ddlEmployees.Items.Insert(0, "---Select---");
        }

    }

    public void GetEmpName()
    {
        string str = Session["Username"].ToString();
        DataTable dt_Name = objDO.fnGetEmpName(str);
        lblEmpName.Text = dt_Name.Rows[0]["E_Name"].ToString();
        lblEmpName.ForeColor = System.Drawing.Color.Magenta;
    }

    protected void btnShow_Click(object sender, EventArgs e)
    {
        if (FromDate.SelectedValue == null || ToDate.SelectedValue == null)
        {
            lblError.Text = "Please Select From/To Dates";
            lblError.ForeColor = System.Drawing.Color.Red;
            gvShowDailyOutput.Visible = false;
        }
        else if (ddlEmployees.SelectedItem.Text == "---Select---")
        {
            lblError.Text = "Please Select Employee";
            lblError.ForeColor = System.Drawing.Color.Red;
            gvShowDailyOutput.Visible = false;
        }
        else
        {
            DataTable dttest = new DataTable();
            dttest = Results();
            if (dt_Grid.Rows.Count > 0)
            {
                if (!IsPostBack)
                {

                }
                gvShowDailyOutput.DataSource = dt_Grid;
                gvShowDailyOutput.DataBind();
                lblError.Text = string.Empty;
                gvShowDailyOutput.Visible = true;
            }
            else
            {
                gvShowDailyOutput.Visible = false;
                lblError.Text = "No Record Found";
                lblError.ForeColor = System.Drawing.Color.Red;
            }
        }
    }

    public DataTable Results()
    {
        DateTime FrmDate = new DateTime();
        FrmDate = FromDate.SelectedDate;
        DateTime TDate = new DateTime();
        TDate = ToDate.SelectedDate;
        userid = ddlEmployees.SelectedItem.Text;
        dt_Grid = bl.selectGridData(userid, FrmDate, TDate);
        return dt_Grid;
    }

    protected void gvShowDailyOutput_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        gvShowDailyOutput.PageIndex = e.NewPageIndex;
        Results();
        gvShowDailyOutput.DataSource = dt_Grid;
        gvShowDailyOutput.DataBind();
    }

    protected void gvShowDailyOutput_RowCreated(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {

            PopupControlExtender pce = e.Row.FindControl("PopupControlExtender1") as PopupControlExtender;
            string behaviorID = "pce_" + e.Row.RowIndex;
            pce.BehaviorID = behaviorID;
            Image img = (Image)e.Row.FindControl("Image1");
            string OnMouseOverScript = string.Format("$find('{0}').showPopup();", behaviorID);
            string OnMouseOutScript = string.Format("$find('{0}').hidePopup();", behaviorID);
            img.Attributes.Add("onmouseover", OnMouseOverScript);
            img.Attributes.Add("onmouseout", OnMouseOutScript);
        }
    }
    [System.Web.Services.WebMethodAttribute(),
    System.Web.Script.Services.ScriptMethodAttribute()]
    public string GetDynamicContent(string contextKey)
    {
        StringBuilder b = new StringBuilder();
        DataTable table = new DataTable();
        table = bl.selectPopupData(ddlEmployees.SelectedItem.Text, contextKey);
        b.Append("<table style="background-color:#f3f3f3; border: #336699 3px solid; ");<br mode="hold" />        b.Append("width:350px; font-size:10pt; font-family:Verdana;" cellspacing="0" cellpadding="3">");
        b.Append("<tr><td colspan="3" style="background-color:#336699; color:white;">");
        b.Append("Report Details"); b.Append("</td></tr>");
        b.Append("<tr><td style="width:80px;">Hour No</td>");
        b.Append("<tr><td style="width:80px;">From Time</td>");
        b.Append("<tr><td style="width:80px;">To Time</td>");
        b.Append("<tr><td style="width:80px;">Report Time</td>");
        b.Append("<tr><td style="width:80px;">Activity</td>");
        b.Append("<tr>");
        b.Append("<td>$" + table.Rows[0]["hourNo"].ToString() + "</td>");
        b.Append("<td>" + table.Rows[0]["fromTime"].ToString() + "</td>");
        b.Append("<td>" + table.Rows[0]["rptTime"].ToString() + "</td>");
        b.Append("<td>" + table.Rows[0]["TaskDetails"].ToString() + "</td>");
        b.Append("</tr>");
        b.Append("</tr></tr></tr></tr></tr></table>");
        return b.ToString();
    }
}

public class _ShowDailyOutput
{
    Dlayer dl = new Dlayer();
    string query;
    public DataTable selectuserid()
    {
        DataTable dt = new DataTable();
        query = "select user_id from user1";
        dt = dl.DA_getTable(query);
        return dt;
    }

    public DataTable selectGridData(string UserID, DateTime FrmDate, DateTime TDate)
    {
        DataTable dt = new DataTable();
        query = "select CONVERT(varchar(20),currentdate,101) AS CurrentDate ,DailyReport.DailyReport_ID, DailyReport.MyOutput from DailyReport INNER JOIN ReportDetails on ReportDetails.DailyReport_ID = DailyReport.DailyReport_ID where user_id = '" + UserID + "' and CurrentDate between '" + FrmDate + "' and '" + TDate + "'";
        dt = dl.DA_getTable(query);
        return dt;
    }
    public DataTable selectPopupData(string ReportID, string ContextKey)
    {
        DataTable dt = new DataTable();
        query = "select ReportDetails.hourNo, ReportDetails.fromtime, ReportDetails.toTime, ReportDetails.rptTime, ReportDetails.TaskDetails from ReportDetails Inner Join DailyReport on ReportDetails.DailyReport_ID = DailyReport.DailyReport_ID where DailyReport.DailyReport_ID = '" + ReportID + "' and user_id = '" + ContextKey + "'";
        dt = dl.DA_getTable(query);
        return dt;
    }
}



See why its not working!



Thanks in advance!!!

Regards!
Posted
Updated 2-Jul-11 7:57am
v2
Comments
Wonde Tadesse 2-Jul-11 10:20am    
What did you attempt so far ? Can you show us your code?

1 solution

Hello Dear ahsan22e
You can use this code for pop up Windows, You should change some codes:
1- Use your page name instead of Default.aspx in second Line in below code.
2- Change width or height according to your page size
3- Change menubar resizable scrolling (top left position) titlebar
Finally You should use this code on a linkbutton_Click event , I mean put a link button then double click on it and write below code on it.
I hope that it can be solved your problem.

VB
Dim script As String = "<script language='javascript'>"
        script = script + " window.open('Default.aspx', 'CustomPopUp', 'width=700, height=590, menubar=no, resizable=yes ,scrolling=yes ,top=12 ,left=12  titlebar=""HomePage" + "') </script>"
        Page.RegisterStartupScript("PopupScript", script)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900