Click here to Skip to main content
15,900,378 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,

I need to add an image to close this table but don't getting anything working.

This is my code:

XML
public static string GetDynamicContent(string contextKey)
{
    string str = contextKey;
    SqlConnection con;
    SqlCommand cmd;
    SqlDataReader reader;
    DataTable table = new DataTable();
    con = new SqlConnection(ConfigurationManager.ConnectionStrings["conn"].ConnectionString);
    con.Open();
    cmd = new SqlCommand("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 = '" + contextKey + "' and user_id = '" + userid + "'", con);
    reader = cmd.ExecuteReader();
    table.Load(reader);
    StringBuilder b = new StringBuilder();
    //b.Append("<script type=\"text/javascript\"> $('#img_11').click(function() {$(\"#ctl00_ContentPlaceHolder1_Panel1\").hide();});</script>");
    b.Append("<table id = 'table1' style='background-color:#f3f3f3; border: #336699 3px solid; ");
    b.Append("width:760px; font-size:8pt; font-family:Verdana;' cellspacing='0' cellpadding='2'>");
    b.Append("<tr><td colspan='4' align = 'left' font-size:20pt; style='background-color:#336699; color:white;'>");
    b.Append("<b>Reprort Details</b></td>"); b.Append("</td>");

    b.Append("<td align = 'right' style='background-color:#336699; color:white;'><img id = 'img_11' style='border-width:0px;' src='../../images1/Close.png' onclick = 'close()';></td>");
    b.Append("</tr>");
    b.Append("<tr>");
    b.Append("<td align = 'left' font-size:10pt; style = 'width:80px; border:#336699 1px solid;'><b>Hour No<b></td>");
    b.Append("<td align = 'left' font-size:10pt; style = 'width:80px;  border:#336699 1px solid;'><b>Start Time</b></td>");
    b.Append("<td align = 'left' font-size:10pt; style = 'width:80px;  border:#336699 1px solid;'><b>End Time</b></td>");
    b.Append("<td align = 'left' font-size:10pt; style = 'width:90px;  border:#336699 1px solid;'><b>Report Time</b></td>");
    b.Append("<td align = 'left' font-size:10pt;  style = 'width:430px;  border:#336699 1px solid;'><b>Activity</b></td>");
    b.Append("</tr>");
    int a = table.Rows.Count;
    for (int i = 0; i < a; i++)
    {
        b.Append("<tr>");
        b.Append("<td align = 'left' style = 'border:#336699 1px solid;'>" + table.Rows[i]["hourNo"].ToString() + "</td>");
        b.Append("<td align = 'left' style = 'border:#336699 1px solid;'>" + table.Rows[i]["fromTime"].ToString() + "</td>");
        b.Append("<td align = 'left' style = 'border:#336699 1px solid;'>" + table.Rows[i]["toTime"].ToString() + "</td>");
        b.Append("<td align = 'left' style = 'border:#336699 1px solid;'>" + table.Rows[i]["rptTime"].ToString() + "</td>");
        b.Append("<td align = 'left' style = 'border:#336699 1px solid;'>" + table.Rows[i]["TaskDetails"].ToString() + "</td>");
        b.Append("</tr>");
    }
    b.Append("</table>");
    return b.ToString();

}


Please anyone help me!!!

Thanks in advance!
Posted
Comments
Sergey Alexandrovich Kryukov 18-Jul-11 13:38pm    
What does it mean "close a table"?! You can close a window, a dialog, an application...
--SA

1 solution

put the image outside the table and call the following javascript onclick of the image like

<img id="img1" src="close.png" alt="Close" onclick="close123();" />


XML
<script type="text/javascript">
        function close123() {
            document.getElementById('table1').style.visibility = "hidden";
        }
    </script>



I think it should work

I have changed a bit in your code plz check


public static string GetDynamicContent(string contextKey)
{
    string str = contextKey;
    SqlConnection con;
    SqlCommand cmd;
    SqlDataReader reader;
    DataTable table = new DataTable();
    con = new SqlConnection(ConfigurationManager.ConnectionStrings["conn"].ConnectionString);
    con.Open();
    cmd = new SqlCommand("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 = '" + contextKey + "' and user_id = '" + userid + "'", con);
    reader = cmd.ExecuteReader();
    table.Load(reader);
    StringBuilder b = new StringBuilder();
    //b.Append("<script type=\"text/javascript\"> $('#img_11').click(function() {$(\"#ctl00_ContentPlaceHolder1_Panel1\").hide();});</script>");

//Changed
b.Append("<table id = 'table2' style='background-color:#f3f3f3; border: #336699 3px solid; ");
            b.Append("width:760px; font-size:8pt; font-family:Verdana;' cellspacing='0' cellpadding='2'>");
            b.Append("<tr><td colspan='4' align = 'left' font-size:20pt; style='background-color:#336699; color:white;'>");
            b.Append("<b>Reprort Details</b></td>"); b.Append("</td>");
            b.Append("<td align = 'right' style='background-color:#336699; color:white;'><img id = 'img_11' style='border-width:0px;' src='red-ball.gif' onclick='javascript:close123()';></td>");
            b.Append("</tr></table>");
            b.Append("<table id = 'table1' style='background-color:#f3f3f3; border: #336699 3px solid; ");
            b.Append("width:760px; font-size:8pt; font-family:Verdana;' cellspacing='0' cellpadding='2'>");
            b.Append("<td align = 'left' font-size:10pt; style = 'width:80px; border:#336699 1px solid;'><b>Hour No<b></td>");
            b.Append("<td align = 'left' font-size:10pt; style = 'width:80px;  border:#336699 1px solid;'><b>Start Time</b></td>");
            b.Append("<td align = 'left' font-size:10pt; style = 'width:80px;  border:#336699 1px solid;'><b>End Time</b></td>");
            b.Append("<td align = 'left' font-size:10pt; style = 'width:90px;  border:#336699 1px solid;'><b>Report Time</b></td>");
            b.Append("<td align = 'left' font-size:10pt;  style = 'width:430px;  border:#336699 1px solid;'><b>Activity</b></td>");
            b.Append("</tr>");
            int a = table.Rows.Count;
            for (int i = 0; i < a; i++)
            {
                b.Append("<tr>");
                b.Append("<td align = 'left' style = 'border:#336699 1px solid;'>" + table.Rows[i]["hourNo"].ToString() + "</td>");
                b.Append("<td align = 'left' style = 'border:#336699 1px solid;'>" + table.Rows[i]["fromTime"].ToString() + "</td>");
                b.Append("<td align = 'left' style = 'border:#336699 1px solid;'>" + table.Rows[i]["toTime"].ToString() + "</td>");
                b.Append("<td align = 'left' style = 'border:#336699 1px solid;'>" + table.Rows[i]["rptTime"].ToString() + "</td>");
                b.Append("<td align = 'left' style = 'border:#336699 1px solid;'>" + table.Rows[i]["TaskDetails"].ToString() + "</td>");
                b.Append("</tr>");
            }
            b.Append("</table>");
            return b.ToString();
 
Share this answer
 
v2
Comments
Ahsan Mirza 18-Jul-11 8:37am    
how can i put it out side and still make it visible in table as this table works as a popup?
Sergey Alexandrovich Kryukov 18-Jul-11 13:40pm    
Both Raju and I apparently fail to understand what do you really want. See my comment to your question.
--SA
Ahsan Mirza 19-Jul-11 3:16am    
well its a popup window that i need to close.
Ahsan Mirza 19-Jul-11 3:23am    
thanks Raju, bro u saved me thanks a lot!
Raju Prajapati 19-Jul-11 3:36am    
Great Pleasure..

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