Extender control 'calExtender2' is not a registered extender control. Extender controls must be registered using RegisterExtenderControl() before calling RegisterScriptDescriptors().

Sep 29, 2009 at 5:16 AM

Hello Everbody,

I want to bind my gridview very fast but it take time on page loading and so i used ICallbackEventHandler, it work fine but in the same gird i have used Ajax toolkit control Calendar extender but after adding it it give th following error "Extender control 'calExtender2' is not a registered extender control. Extender controls must be registered using RegisterExtenderControl() before calling RegisterScriptDescriptors()."

I got the error in following line:

System.Text.GridView3.RenderControl(htWriter);

Please find the code

<font size="2">

 

</font>

 

 

"EmpDailyActivity.aspx"

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="EmpDailyActivity.aspx.cs" Inherits="ActivityTracker_EmpDailyActivity" %>

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
    <title>Emp Daily Activity</title>
  
<script language="javascript" type="text/javascript">
var submenutime = 2000; // time to show sub menu after mouse-out
//parent.document.getElementById('Text1').value='123456789';
var timerID = null;    // needed by timer
//window.onload = function() {
//alert('abc');
//};
/*function ModName()
{
    //alert('12345');
    //qs();
    parent.document.getElementById('Text1').value=qsParm['Mod'];
}*/
function ResetTimer()
{
    clearTimeout(timerID);
}

function StartTimer()
{
    timerID = setTimeout('Hide()', submenutime);
}

function Hide()
{
    document.getElementById('divTree1').style.display='none';
}
function show()
{
    //alert('12345');
    document.getElementById('divTree1').style.display='block';
}
function ChangeDate()
{
   
}
function checkDate(sender,args)
{
    if (sender._selectedDate > new Date())
    {
        alert("You cannot select a day greater than today!");
        sender._selectedDate = new Date();
        // set the date back to the current date
        sender._textbox.set_Value(sender._selectedDate.format(sender._format))
    }
}
var qsParm = new Array();
/*function qs()
{
    var query = window.location.search.substring(1);
    var parms = query.split(’&’);
    for (var i=0; i<parms.length; i++)
    {
        var pos = parms[i].indexOf(’=');
        if (pos > 0)
        {
            var key = parms[i].substring(0,pos);
            var val = parms[i].substring(pos+1);
            qsParm[key] = val;
        }
    }
 }*/
 
    function GetData(btn)
    {
       
        //var ctrl = document.getElementById('txtFilter');
        //alert(ctrl.value);
        //CallServer(ctrl.value,context);
        var context=new Object();
        CallServer('9','Today');
        alert('22222222');
    }
    function CallbackOnSucceeded(result,context)
    {
        //alert(result);
        GridData.innerHTML = result;
    }
    function CallbackOnFailed(result,context)
    {
        //divDisplay.innerHTML =result;
    }


</script>

        <style type="text/css">
        .GVFixedHeader { font-weight:bold; background-color: #cccccc; position:relative; top:expression(this.parentNode.parentNode.parentNode.scrollTop-1);}
        .GVFixedFooter { font-weight:bold; background-color: Grey; position:relative; bottom:expression(getScrollBottom(this.parentNode.parentNode.parentNode.parentNode));}
    </style>
    <link href="../StyleSheet/RegulatoryMIS.css" rel="stylesheet" type="text/css" />
</head>


<body>
    <form id="form1" runat="server">
        &nbsp;
        <!-- <input id="Button1" style="left: 453px; position: absolute; top: 481px" type="button"
             onclick="ModName()" value="button" />-->
        &nbsp;
        <asp:Label ID="Label1" runat="server" Height="22px" Style="left: 238px; position: absolute;
            top: 16px" Text="Employee" Width="96px"></asp:Label>
        <asp:Label ID="lblErr" runat="server" Height="22px" Style="left: 601px; position: absolute;
            top: 16px" Width="263px" ForeColor="Red"></asp:Label>
        <input id="btnShowAj" onclick="GetData(this)" type="button" value="Show" style="left: 19px; width: 53px; position: absolute" />
        <asp:Label ID="Label2" runat="server" Height="22px" Style="left: 73px; position: absolute;
            top: 16px" Text="Activity Date" Width="37px"></asp:Label>
        <asp:DropDownList ID="cmbEmp" runat="server" CssClass="DDList"
            Style="left: 339px; position: absolute; top: 15px" Width="204px">
        </asp:DropDownList>
        <asp:TextBox ID="txtForDate" runat="server" style="left: 111px; position: absolute; top: 16px" Width="114px" OnTextChanged="txtForDate_TextChanged" ToolTip="DateFormat:MM/DD/YYYY" ></asp:TextBox>
       
    <div>
        <asp:Button ID="btnNew" runat="server" OnClick="btnNew_Click" Text="New" style="position: absolute; left: 16px; top: 464px;" AccessKey="N" Width="60px" Height="24px" Enabled="False" />
        <img id="imgSearch" src="../Graphics/Search.gif" style="left: 1037px; width: 25px; position: absolute;
            top: 14px; height: 26px" onmouseover="show();"  />
            <!--show();StartTimer()-->
        <asp:Button ID="btnApprove" runat="server" OnClick="btnApprove_Click" Text="Approve" style="position: absolute; left: 147px; top: 464px;" AccessKey="N" Width="60px" Height="24px" Enabled="False" />
        &nbsp;
        &nbsp;&nbsp;&nbsp;
        <br />
        <asp:Panel runat="server" ID="pnlContainer" ScrollBars="Auto"  Height="413px" Width="1077px" style="left: 11px; position: absolute; top: 43px">
            &nbsp;
            <span id="GridData"></span>
            <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="sino" CellPadding="4" ForeColor="#333333" GridLines="None" OnRowCreated="GridView1_RowCreated" OnRowDataBound="GridView1_RowDataBound" Height="163px">
       
            <HeaderStyle CssClass="GVFixedHeader" BackColor="#cccccc" Font-Names="Times New Roman" Font-Size="Medium" />
             <FooterStyle CssClass="GVFixedFooter" BackColor="Khaki"/>
                <Columns>
                    <asp:TemplateField HeaderText="Activity">
                        <ItemTemplate>
                        <asp:TextBox ID="txtActivity" runat="server" Text='<%# Bind("Activity") %>' ></asp:TextBox>
                        </ItemTemplate>
                    </asp:TemplateField>

                    <asp:TemplateField HeaderText="Type" >
                        <ItemTemplate>
                            <asp:DropDownList ID="ddlActivityType" runat="server" Width="74px" Text='<%# Bind("ActivityType") %>'>
                                <asp:ListItem Value="0"><--Select--></asp:ListItem>
                                <asp:ListItem Value="1">Daily</asp:ListItem>
                                <asp:ListItem Value="2">Weekly</asp:ListItem>
                                <asp:ListItem Value="3">Monthly</asp:ListItem>
                                <asp:ListItem Value="4">Yearly</asp:ListItem>
                                <asp:ListItem Value="5">Project</asp:ListItem>
                            </asp:DropDownList>
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="Sche Date" >
                       
                        <ItemTemplate>
                            <asp:TextBox ID="txtScheDate" runat="server" Width="60px" Text='<%# Bind("ScheDate") %>' ></asp:TextBox>
                           <cc1:calendarextender runat="server" ID="calExtender2" PopupButtonID="txtScheDate"
                                CssClass="AjaxCalendar" TargetControlID="txtScheDate" Format="dd-MM-yyyy" />
                              
                        </ItemTemplate> 
                        <ControlStyle Width="100px" />
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="Sche Time">
                        <ItemTemplate>
                            <asp:TextBox ID="txtScheTime" runat="server" Width="74px" Text='<%# Bind("ScheTime") %>' ></asp:TextBox>
                    <!--          <cc1:MaskedEditExtender ID="meScheTime" runat="server" CultureName="en-AU" Enabled="true" Mask="99:99" MaskType="time" AcceptAMPM="true" AutoComplete="true"  TargetControlID="txtScheTime" />
                            <cc1:MaskedEditValidator ID="mevScheTime" runat="server" ControlExtender="meScheTime" ControlToValidate="txtScheTime" Display="Dynamic" EmptyValueMessage="A TIme Required"
                    InvalidValueMessage="This invalid" IsValidEmpty="false" TooltipMessage="Please enter the time" />
                        -->
                         </ItemTemplate>
                   
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="Done Date" >
                       
                        <ItemTemplate>
                            <asp:TextBox ID="txtDoneDate" runat="server" Width="74px" Text='<%# Bind("DoneDate") %>' ></asp:TextBox>
                          <!--  <cc1:calendarextender runat="server" ID="calDoneDate" PopupButtonID="txtDoneDate"
                                CssClass="AjaxCalendar" TargetControlID="txtDoneDate" Format="dd-MM-yyyy" />
                            -->                      
                        </ItemTemplate> 
                        <ControlStyle Width="100px" />
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="Done Time">
                        <ItemTemplate>
                            <asp:TextBox ID="txtDoneTime" runat="server" Width="74px" Text='<%# Bind("DoneTime") %>' ></asp:TextBox>
                        <!--    <cc1:MaskedEditExtender ID="meDoneTime" runat="server" CultureName="en-AU" Enabled="true" Mask="99:99" MaskType="time" AcceptAMPM="true" AutoComplete="true"  TargetControlID="txtDoneTime" />
                            <cc1:MaskedEditValidator ID="mevDoneTime" runat="server" ControlExtender="meDoneTime" ControlToValidate="txtDoneTime" Display="Dynamic" EmptyValueMessage="A TIme Required"
                    InvalidValueMessage="This invalid" IsValidEmpty="True" TooltipMessage="Please enter the time" />
                     -->  
                         </ItemTemplate>
                         </asp:TemplateField>
                    <asp:TemplateField HeaderText="Trans Type">
                        <ItemTemplate>
                            <asp:TextBox ID="txtTransType" runat="server" Text='<%# Bind("TransType") %>' ></asp:TextBox>
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="Emp Remarks">
                        <ItemTemplate>
                        <asp:TextBox ID="txtEmpRem" runat="server" Text='<%# Bind("EmpRemarks") %>' ></asp:TextBox>
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField>
                        <HeaderTemplate>
                            Status
                        </HeaderTemplate>
                        <ItemTemplate>
                            <asp:DropDownList ID="ddlStatus" runat="server" Width="74px" OnSelectedIndexChanged="ddlStatus_SelectedIndexChanged"></asp:DropDownList>
                        </ItemTemplate>
                   </asp:TemplateField>
                   <asp:BoundField DataField="StatusID" HeaderText="StatusID">
                        <ControlStyle Width="100px" />
                        <ItemStyle Font-Names="Arial" ForeColor="Black" Width="500px" Height="10px" />
                   </asp:BoundField>
                   <asp:TemplateField HeaderText="Checker Remarks">
                        <ItemTemplate>
                        <asp:TextBox ID="txtChkRem" runat="server" Text='<%# Bind("CheckerRemarks") %>' ></asp:TextBox>
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="SysDoneDate">
                        <ItemTemplate>
                        <asp:TextBox ID="txtSysDoneDate" runat="server" Text='<%# Bind("SysDoneDate") %>' ></asp:TextBox>
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="PendActivityID">
                        <ItemTemplate>
                        <asp:TextBox ID="txtPendActivityID" runat="server" Text='<%# Bind("PendActivityID") %>' ></asp:TextBox>
                        </ItemTemplate>
                    </asp:TemplateField>
                </Columns>
            <SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="Navy" />
            <AlternatingRowStyle BackColor="White" />
            <RowStyle Wrap="True" Font-Names="Times New Roman" Font-Size="Small" Width="15px" Height="15px" BackColor="#FFFBD6" ForeColor="#333333"  />
        </asp:GridView>
    </asp:Panel>
 <asp:Button ID="btnSave" runat="server"  OnClick="btnSave_Click" Text="Save" style="left: 80px; position: absolute; top: 464px" Width="60px" AccessKey="S" Enabled="False" />
 <asp:Button ID="btnShow" runat="server"  OnClick="btnShow_Click" Text="Show" style="left: 546px; position: absolute; top: 14px" Width="52px" AccessKey="H" Height="23px" />
        <div style="left: 174px; width: 100px; position: absolute; top: 471px; height: 57px">
    <asp:ScriptManager ID="ScriptManager1" runat="server" />
          <!--  <cc1:calendarextender runat="server" ID="calForDate" PopupButtonID="txtForDate"
            CssClass="AjaxCalendar" TargetControlID="txtForDate" Format="MM/dd/yyyy" />
            -->
        </div>
        <div id="divTree1" style="scrollbar-face-color: #ffffff; left: 874px; scrollbar-highlight-color: #6699cc;
            overflow: auto; width: 163px; scrollbar-3dlight-color: #6699cc; scrollbar-arrow-color: #000000;
            scrollbar-track-color: #b7d5f7; scrollbar-darkshadow-color: #6699cc; position: absolute;
            top: 16px; height: 454px; background-color: #f0f8ff;display:none;" onmousemove="ResetTimer()" onmouseout="StartTimer()" >
            <asp:TreeView ID="tv_JobOrderTree" runat="server" ExpandDepth="1"  OnTreeNodePopulate="Node_Populate">
                <Nodes>
                    <asp:TreeNode PopulateOnDemand="True" SelectAction="None" Text="Employee" Value="0" ></asp:TreeNode>
                </Nodes>
            </asp:TreeView>
        </div>

    </div>
    </form>
</body>
</html>

 

"EmpDailyActivity.aspx.cs"

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;


public partial class ActivityTracker_EmpDailyActivity : System.Web.UI.Page,ICallbackEventHandler
{
    DataSet dsEmp;
    DataTable  dtStaus;
    Int16 LogAs;
    Int16 intForDayStatus;
   
    protected System.Web.UI.HtmlControls.HtmlForm form2;
    public enum ColList:int
    {
        sino = 1,
        Activity = 2,
        ActivityType = 3,
        ScheDate = 4,
        ScheTime = 5,
        TransType = 6,
        DoneDate = 7,
        DoneTime = 8   
    }
    protected void Page_Init(object sender, EventArgs e)
    {
        //RegisterExtenderControl
        //ScriptManager1
       
        //ScriptManager1.RegisterExtenderControl<TExtenderControl>(calExtender2, GridView1);
    }

    //public override void RegisterExtenderControl<TExtenderControl>(TExtenderControl extenderControl, Control targetControl)
    //{
    //    ScriptManager1.RegisterExtenderControl<TExtenderControl>(extenderControl, targetControl);
    //}

    protected void Page_Load(object sender, EventArgs e)
    {
        string tmpDate;
        Int16 tmpEmpId;
        RegisterCallBackReference();
        //tmpDate= Convert.ToString(Request.QueryString["dt"]);
        if (Request.QueryString["dt"].ToString() != "")
        {
            tmpDate = DateTime.Parse(Request.QueryString["dt"]).ToString("dd/MMM/yyyy");
        }
        else
        {
            tmpDate = "";
        }
       
        LogAs = Convert.ToInt16(Request.QueryString["LogAs"]);
        if (LogAs == 1)
        {
            btnNew.Enabled = false;
            btnApprove.Enabled = true;
        }

        if (!Page.IsPostBack)
        {
            DBController dbcont = new DBController();
            if (LogAs == 0)
            {
                dsEmp = dbcont.DataList("ACT_GetEmp", 0, Session["USERID"].ToString());
            }
            else if (LogAs == 1)
            {
                dsEmp = dbcont.DataList("ACT_GetEmp", 1, Session["USERID"].ToString());
            }
            else
            {
                dsEmp = dbcont.DataList("ACT_GetEmp");
            }
            Session["vdsEmp"] = dsEmp;
            cmbEmp.DataSource = dsEmp;
            cmbEmp.DataTextField = "EmpFName";
            cmbEmp.DataValueField = "EmpID";
            cmbEmp.DataBind();
            cmbEmp.Items.Insert(0, "< Select >");
           
            EmptyGrid();
            // RegID and STatus for is 100 for this module
            dtStaus = dbcont.getStausType("GetStatus", 101, 101).Tables[0];
            ViewState["vdtStaus"] = dtStaus;

            if (tmpDate != "")
            {
                txtForDate.Text = tmpDate;
                tmpDate = "";
            }
            tmpEmpId = Convert.ToInt16(Request.QueryString["ID"]);
            cmbEmp.SelectedIndex = cmbEmp.Items.IndexOf(cmbEmp.Items.FindByValue(Convert.ToString(tmpEmpId)));
            tmpEmpId = 0;
            if (cmbEmp.SelectedIndex != 0)
            {
                //cmbEmp_SelectedIndexChanged(cmbEmp, null);
                btnShow_Click(btnShow, null);
            }
            if (LogAs == 0)
            {
                cmbEmp.SelectedIndex = 1;
                txtForDate.Text = DateTime.Now.ToString("dd-MMM-yyyy");
            }

            //ddlGrStatus.DataSource = dsStaus;
            //ddlGrStatus.DataTextField = "StatusDesc";
            //ddlGrStatus.DataValueField = "StatusID";
            //ddlGrStatus.DataBind();
            //ddlGrStatus.Items.Insert(0, "< Select >");

        }
        else
        {
            dtStaus = (DataTable)ViewState["vdtStaus"];
            dsEmp = (DataSet)Session["vdsEmp"];
        }
       
       
        //drdList.SelectedIndex = drdList.Items.IndexOf(drdList).Items.FindByValue(e.Row.Cells[9].Text.ToString()));
    }

    //To Bind Empty Grid with three rows when page loads

    public void EmptyGrid()
    {
        DataTable TempTable = new DataTable();
        TempTable.Columns.Add("sino");
        TempTable.Columns.Add("Activity");
        //TempTable.Columns.Add("gender");
        TempTable.Columns.Add("ActivityType");
        TempTable.Columns.Add("ScheDate");
        TempTable.Columns.Add("ScheTime");
        TempTable.Columns.Add("TransType");
        TempTable.Columns.Add("DoneDate");
        TempTable.Columns.Add("DoneTime");
        TempTable.Columns.Add("StatusID");
        TempTable.Columns.Add("EmpRemarks");
        TempTable.Columns.Add("CheckerRemarks");
        TempTable.Columns.Add("SysDoneDate");
        TempTable.Columns.Add("PendActivityID");
       
       
        //TempTable.PrimaryKey = new DataColumn[] { TempTable.Columns["sino"] };
        //TempTable = BindEmptyRows(1, TempTable);
        GridView1.DataSource = TempTable;
        GridView1.DataBind();
    }

    //Method to Bind Rows

    private DataTable BindEmptyRows(int nofoRows, DataTable dt)
    {
        for (int i = 0; i < nofoRows; i++)
        {
            DataRow dr = dt.NewRow();
            dr["sino"] = dt.Rows.Count + 1;
            dr["Activity"] = string.Empty;
            //dr["gender"] = "0";
            dr["ActivityType"] = "0";
            dr["ScheDate"] = string.Empty;
            dr["ScheTime"] = string.Empty;
            dr["DoneDate"] = string.Empty;
            dr["DoneTime"] = string.Empty;
            dr["TransType"] = "1";
            dr["StatusID"] = "0";
            dr["EmpRemarks"] = string.Empty;
            dr["CheckerRemarks"] = string.Empty;
            dr["SysDoneDate"] = string.Empty;
            dr["PendActivityID"] = string.Empty;
           
            dt.Rows.Add(dr);
        }
        return dt;
    }

    //On Clicking Save Button this event fires

    protected void btnSave_Click(object sender, EventArgs e)
    {
        SaveGridDataInTempTable();
        DataTable dtSave = Temp.Copy();
        Int32  retval;
        DBController dbcont = new DBController();
       
        retval = dbcont.SaveEmpDailyActivity(Convert.ToInt16(cmbEmp.SelectedValue.ToString()), dtSave, DateTime.Parse(txtForDate.Text).ToString("yyyy-MM-dd"));
        //retval = dbcont.testDate("2009-09-01");
    }
   
    //Save Grid in Temporary Datatable
    private void SaveGridDataInTempTable()
    {
        DataTable dtTemp = new DataTable();
        GenFunction gFun = new GenFunction();
        if (dtTemp == null || dtTemp.Columns.Count <= 0)
        {
            dtTemp.Columns.Add("sino");
            dtTemp.Columns.Add("Activity", typeof(String));
            //dtTemp.Columns.Add("gender", typeof(String));
            dtTemp.Columns.Add("ActivityType", typeof(String));
            dtTemp.Columns.Add("ScheDate", typeof(String));
            dtTemp.Columns.Add("ScheTime", typeof(String));
            dtTemp.Columns.Add("TransType", typeof(String));
            dtTemp.Columns.Add("DoneDate", typeof(String));
            dtTemp.Columns.Add("DoneTime", typeof(String));
            dtTemp.Columns.Add("StatusID", typeof(String));
            dtTemp.Columns.Add("EmpRemarks", typeof(String));
            dtTemp.Columns.Add("CheckerRemarks", typeof(String));
            dtTemp.Columns.Add("SysDoneDate", typeof(String));
            dtTemp.Columns.Add("PendActivityID", typeof(String));
           
            //dtTemp.PrimaryKey = new DataColumn[] { dtTemp.Columns["sino"] };
        }
        foreach (GridViewRow gvRow in GridView1.Rows)
        {
            DataRow drTemp = dtTemp.NewRow();
            drTemp["sino"] = int.Parse(GridView1.DataKeys[gvRow.RowIndex]["sino"].ToString());
            drTemp["Activity"] = ((TextBox)gvRow.FindControl("txtActivity")).Text.Trim();
            drTemp["ActivityType"] =((DropDownList)gvRow.FindControl("ddlActivityType")).SelectedValue.ToString();
            if ((((TextBox)gvRow.FindControl("txtScheDate")).Text.Length < 11))
            {
                drTemp["ScheDate"] = gFun.DateChangeFormat(((TextBox)gvRow.FindControl("txtScheDate")).Text.Trim());
            }
            else
            {
                drTemp["ScheDate"] = ((TextBox)gvRow.FindControl("txtScheDate")).Text.Trim();
            }
            drTemp["ScheTime"] = ((TextBox)gvRow.FindControl("txtScheTime")).Text.Trim();
            drTemp["TransType"] = ((TextBox)gvRow.FindControl("txtTransType")).Text.Trim();
            if (((TextBox)gvRow.FindControl("txtDoneDate")).Text.Trim() != "")
            {
                //drTemp["DoneDate"] = DateChangeFormat(DateTime.Parse(((TextBox)gvRow.FindControl("txtDoneDate")).Text).ToString("dd-MM-yyyy"));
                if (((TextBox)gvRow.FindControl("txtDoneDate")).Text.Length < 11)
                {
                    drTemp["DoneDate"] = gFun.DateChangeFormat(((TextBox)gvRow.FindControl("txtDoneDate")).Text);
                }
                else if (((TextBox)gvRow.FindControl("txtDoneDate")).Text.Length == 11)
                {
                    drTemp["DoneDate"] = ((TextBox)gvRow.FindControl("txtDoneDate")).Text;
                }
            }
            else
            {
                drTemp["DoneDate"] = "";
            }
            //DateTime.Parse(txtGrDate.Text).ToString("yyyy-MMM-dd")
            drTemp["DoneTime"] = ((TextBox)gvRow.FindControl("txtDoneTime")).Text.Trim();
            drTemp["StatusID"] = ((DropDownList)gvRow.FindControl("ddlStatus")).SelectedItem.Value.ToString();
            if (LogAs == 1)
            {
                if (drTemp["StatusID"].ToString() == "8")
                {
                    drTemp["StatusID"] =11;
                }
            }
            drTemp["EmpRemarks"] = ((TextBox)gvRow.FindControl("txtEmpRem")).Text.Trim();
            drTemp["CheckerRemarks"] = ((TextBox)gvRow.FindControl("txtChkRem")).Text.Trim();
            if (((TextBox)gvRow.FindControl("txtSysDoneDate")).Text.Trim() != "")
            {//gFun.DateChangeFormat
                drTemp["SysDoneDate"] = (((TextBox)gvRow.FindControl("txtSysDoneDate")).Text.Trim());
            }
            if (drTemp["SysDoneDate"] != "")
            {
                if ((drTemp["StatusID"].ToString() == "9") || (drTemp["StatusID"].ToString() == "10"))
                {
                    drTemp["SysDoneDate"] = DateTime.Now.ToString("yyyy-MM-dd hh:mm");
                }
            }
            drTemp["PendActivityID"] = ((TextBox)gvRow.FindControl("txtPendActivityID")).Text.Trim();
           
            //drdList = (DropDownList)(grdStepRes.Rows[rownumber].Cells[1].FindControl("ddlComplNo"));
            //drComplRes[1] = drdList.SelectedItem.Value;
            dtTemp.Rows.Add(drTemp);
        }
        Temp = dtTemp;
    }
    protected void btnNew_Click(object sender, EventArgs e)
    {
        SaveGridDataInTempTable();
        DataTable dtNew = Temp.Copy();
        bool isinsert = true;
        foreach (DataRow dr in dtNew.Rows)
        {
            if (String.IsNullOrEmpty(dr["Activity"].ToString()) || dr["ActivityType"].ToString() == "0")
            {
                isinsert = false;
            }
        }
        if (isinsert)
            BindEmptyRows(1, dtNew);
        Temp = dtNew;
        GridView1.DataSource = dtNew;
        GridView1.DataBind();
        GridView1.Rows[GridView1.Rows.Count - 1].FindControl("txtActivity").Focus();
    }

    //Property to maintain the Datatable
    public DataTable Temp
    {
        get
        {
            object o = ViewState["Temp"];
            if (o == null)
            {
                DataTable dt = new DataTable();
                return dt;
            }
            else
                return (DataTable)o;
        }
        set
        {
            ViewState["Temp"] = value;
        }
    }

    protected void cmbEmp_SelectedIndexChanged(object sender, EventArgs e)
    {
       
    }
    protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
    {
        e.Row.Cells[6].Visible = false; //TransType
        e.Row.Cells[9].Visible = false; //StatusID
        e.Row.Cells[11].Visible = false; //SysDoneTime
        e.Row.Cells[12].Visible = false; //PendActivityID
    }
    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        TextBox textAct;
        TextBox TranType;
        DropDownList drdList;
        if (e.Row.RowIndex != -1)
        {
           
           
            drdList = (DropDownList)(e.Row.Cells[7].FindControl("ddlStatus"));
            drdList.DataSource = dtStaus;
            drdList.DataValueField = "StatusID";
            drdList.DataTextField = "StatusDesc";
            drdList.DataBind();
            drdList.SelectedIndex = drdList.Items.IndexOf(drdList.Items.FindByValue(e.Row.Cells[9].Text.ToString()));
           
            //DropDownList dropDownList = (DropDownList)e.Row.FindControl("ddlStatus");   // look for dropdown in the row
            //dropDownList.AutoPostBack = true;     // added here for clarity
            //dropDownList.SelectedIndexChanged += new EventHandler(ddlStatus_SelectedIndexChanged);   // declare event

            drdList = (DropDownList)(e.Row.Cells[7].FindControl("ddlActivityType"));

            if (LogAs == 1)
            {
                textAct = (TextBox)e.Row.Cells[0].FindControl("txtActivity");
                textAct.ReadOnly = true;
                //drdList = (TextBox)e.Row.Cells[0].FindControl("ddlActivityType");
                //drdList.red = true;
                textAct = (TextBox)e.Row.Cells[0].FindControl("txtScheDate");
                textAct.Enabled = false;
                textAct = (TextBox)e.Row.Cells[0].FindControl("txtScheTime");
                textAct.ReadOnly = true;
                textAct = (TextBox)e.Row.Cells[0].FindControl("txtTransType");
                textAct.ReadOnly = true;
                textAct = (TextBox)e.Row.Cells[0].FindControl("txtDoneDate");
                textAct.Enabled = false;
                textAct = (TextBox)e.Row.Cells[0].FindControl("txtDoneTime");
                textAct.ReadOnly = true;
                textAct = (TextBox)e.Row.Cells[0].FindControl("txtEmpRem");
                textAct.ReadOnly = true;
                drdList.Enabled = false;
            }
            else if (LogAs == 0)
            {
                TranType = (TextBox)e.Row.Cells[4].FindControl("txtTransType");
                if (TranType.Text != "1")
                {
                    textAct = (TextBox)e.Row.Cells[0].FindControl("txtActivity");
                    textAct.Enabled  = false;
                    textAct = (TextBox)e.Row.Cells[0].FindControl("txtScheDate");
                    textAct.Enabled = false;
                    textAct = (TextBox)e.Row.Cells[0].FindControl("txtScheTime");
                    textAct.Enabled = false;
                    drdList.Enabled = false;
                }
                else
                {
                    textAct = (TextBox)e.Row.Cells[0].FindControl("txtActivity");
                    textAct.Enabled = true;
                    textAct = (TextBox)e.Row.Cells[0].FindControl("txtScheDate");
                    textAct.Enabled = true;
                    textAct = (TextBox)e.Row.Cells[0].FindControl("txtScheTime");
                    textAct.Enabled  = true;
                    drdList.Enabled = true;
                }
            }
        }
        //left: expression(parentNode.parentNode.parentNode.parentNode.scrollLeft);
    }

    protected void ddlStatus_SelectedIndexChanged(object sender, EventArgs e)
    {
        TextBox textSysDoneDate;
        GridViewRow gridViewRow = (GridViewRow)(((Control)sender).NamingContainer); 
        textSysDoneDate = (TextBox)gridViewRow.FindControl("txtSysDoneDate");
        textSysDoneDate.Text  = DateTime.Now.ToString();
    }

    protected void btnApprove_Click(object sender, EventArgs e)
    {
        Int32 retval;
        DBController dbcont = new DBController();
        btnSave_Click(btnApprove, null);
        retval = dbcont.ApproveEmpDailyActivity(Convert.ToInt16(cmbEmp.SelectedValue.ToString()),  DateTime.Parse(txtForDate.Text).ToString("yyyy-MM-dd"));
    }

    public void Node_Populate(object sender, System.Web.UI.WebControls.TreeNodeEventArgs e)
    {
        DataSet dsJobOrder = new DataSet();
        if (dsEmp.Tables[0].Rows.Count > 0)
        {
            if (e.Node.ChildNodes.Count == 0)
            {
                switch (e.Node.Depth)
                {
                    case 0:
                        FillJobOrders(e.Node, dsEmp);
                        break;
                    case 1:
                        DBController dbcont = new DBController();
                        dsJobOrder = dbcont.DataList("ACT_GET_EMPDATE_ACTIVITY");
                        FillTimesheetsForJobOrder(e.Node, dsJobOrder);
                        break;
                }
            }

            tv_JobOrderTree.MaxDataBindDepth = 2;
        }
        else
        {
            tv_JobOrderTree.Visible = false;
        }
    }
    public void FillJobOrders(TreeNode node, DataSet dsJO)
    {
        if (dsJO.Tables.Count > 0)
        {
            DataTable dt = new DataTable();
            dt = dsJO.Tables[0];
            foreach (DataRow row in dt.Rows)
            {
                //TreeNode newNode = new TreeNode(row["EmpCode"].ToString());
                TreeNode newNode = new TreeNode(row["EmpFName"].ToString());
                newNode.PopulateOnDemand = true;
                newNode.Value = row["EmpID"].ToString();
                newNode.SelectAction = TreeNodeSelectAction.None;
                node.ChildNodes.Add(newNode);
            }
        }
    }

    public void FillTimesheetsForJobOrder(TreeNode node, DataSet dsJO)
    {
        if (dsJO.Tables.Count > 0)
        {
            foreach (DataRow row in dsJO.Tables[0].Rows)
            {
                if (node.Value == row["EmpID"].ToString())
                {
                    //TreeNode newNode = new TreeNode(row["ForDate"].ToString());
                    //newNode.Value = row["ForDate"].ToString(); //;
                    //newNode.NavigateUrl = "EmpDailyActivity.aspx?dt=" + DateTime.Parse(row["ForDate"].ToString()).ToString("dd/MM/yyyy") + "&ID=" + node.Value + "&LogAs="+LogAs;
                    //newNode.PopulateOnDemand = true;
                    //newNode.SelectAction = TreeNodeSelectAction.Select;
                    //newNode.ExpandAll();

                    TreeNode newNode = new TreeNode((row["ForDate"].ToString()));
                    newNode.Value = (row["ForDate"].ToString()); //;
                    newNode.NavigateUrl = "EmpDailyActivity.aspx?dt=" + (row["ForDate"].ToString()) + "&ID=" + node.Value + "&LogAs=" + LogAs;
                    newNode.PopulateOnDemand = true;
                    newNode.SelectAction = TreeNodeSelectAction.Select;
                    newNode.ExpandAll();

                    node.ChildNodes.Add(newNode);
                }
            }
        }
    }
    protected void txtForDate_TextChanged(object sender, EventArgs e)
    {
        //txtForDate.Text = DateTime.Parse(txtForDate.Text).ToString("dd/MMM/yyyy");
      
        //cmbEmp_SelectedIndexChanged(cmbEmp, null);
    }

    protected void ShowGriddata()
    {
        DBController dbcont = new DBController();
        DataTable dtGetEmpAct = new DataTable();
        dtGetEmpAct = dbcont.DataList("ACT_GET_EmpActivity", Int32.Parse(cmbEmp.SelectedItem.Value), DateTime.Parse(txtForDate.Text).ToString("yyyy-MM-dd"), LogAs).Tables[0];

        DataTable dtTemp = new DataTable();
        if (dtTemp == null || dtTemp.Columns.Count <= 0)
        {
            dtTemp.Columns.Add("sino");
            dtTemp.Columns.Add("Activity", typeof(String));
            dtTemp.Columns.Add("ActivityType", typeof(String));
            dtTemp.Columns.Add("ScheDate", typeof(String));
            dtTemp.Columns.Add("ScheTime", typeof(String));
            dtTemp.Columns.Add("TransType", typeof(String));
            dtTemp.Columns.Add("DoneDate", typeof(String));
            dtTemp.Columns.Add("DoneTime", typeof(String));
            dtTemp.Columns.Add("StatusID", typeof(String));
            dtTemp.Columns.Add("EmpRemarks", typeof(String));
            dtTemp.Columns.Add("CheckerRemarks", typeof(String));
            dtTemp.Columns.Add("SysDoneDate", typeof(String));
            dtTemp.Columns.Add("PendActivityID", typeof(String));

            //dtTemp.PrimaryKey = new DataColumn[] { dtTemp.Columns["sino"] };
        }
        if (dtGetEmpAct.Rows.Count > 0)
        {
            if (LogAs == 1)
            {
                if (dtGetEmpAct.Rows[0][0].ToString() == "-1")
                {
                    lblErr.Text = "Activity not exist";
                    GridView1.Visible = false;
                    btnApprove.Enabled = false;
                    btnNew.Enabled = false;
                    btnSave.Enabled = false;
                    return;
                }
                else
                {
                    GridView1.Visible = true;
                }
            }
            else
            {
                GridView1.Visible = true;
                btnApprove.Enabled = false;
                btnNew.Enabled = true;
                btnSave.Enabled = true;
            }
            intForDayStatus = Convert.ToInt16(dtGetEmpAct.Rows[0]["ForDayStatus"].ToString());
            if (intForDayStatus == 1)
            {
                btnApprove.Enabled = false;
                btnNew.Enabled = false;
                btnSave.Enabled = false;
            }
            foreach (DataRow dr in dtGetEmpAct.Rows)
            {
                DataRow drTemp = dtTemp.NewRow();
                drTemp["sino"] = int.Parse(dr["ActivityNo"].ToString());
                drTemp["Activity"] = dr["Activity"].ToString();
                drTemp["ActivityType"] = int.Parse(dr["ActivityType"].ToString());
                //drTemp["ScheDate"] = dr["ActivityScheDate"].ToString();
                drTemp["ScheDate"] = DateTime.Parse(dr["ActivityScheDate"].ToString()).ToString("dd-MMM-yyyy");
                //drTemp["ScheTime"] = dr["ActivityScheTime"].ToString();
                drTemp["ScheTime"] = DateTime.Parse(dr["ActivityScheTime"].ToString()).ToString("hh:mm tt");
                //C.WriteLine("t = {0:t}", dateTime);  // hh:mm AM/PM
                drTemp["TransType"] = dr["TransType"].ToString();
                if (dr["DoneDate"].ToString() != "" && dr["DoneDate"].ToString() != "01/01/1900 12:00:00 AM")
                {
                    drTemp["DoneDate"] = DateTime.Parse(dr["DoneDate"].ToString()).ToString("dd/MM/yyyy");
                }
                if (dr["DoneTime"].ToString() != "" && dr["DoneDate"].ToString() != "01/01/1900 12:00:00 AM")
                {
                    drTemp["DoneTime"] = DateTime.Parse(dr["DoneTime"].ToString()).ToString("hh:mm tt");
                }
                drTemp["StatusID"] = dr["StatusID"].ToString();
                drTemp["EmpRemarks"] = dr["EmpRemarks"].ToString();
                drTemp["CheckerRemarks"] = dr["CheckerRemarks"].ToString();
                if (dr["SysDoneDate"].ToString() != "" && dr["SysDoneDate"].ToString() != "01/01/1900 12:00:00 AM")
                {
                    drTemp["SysDoneDate"] = DateTime.Parse(dr["SysDoneDate"].ToString()).ToString("dd/MM/yyyy hh:mm tt");
                }
                drTemp["PendActivityID"] = dr["PendActivityID"].ToString();

                dtTemp.Rows.Add(drTemp);
            }
        }
        else
        {
            dtTemp = BindEmptyRows(1, dtTemp);
        }
        GridView1.DataSource = dtTemp;
        GridView1.DataBind();
        Temp = dtTemp;
    }
    protected void btnShow_Click(object sender, EventArgs e)
    {
       
        //txtForDate.Text = DateTime.Parse(txtForDate.Text).ToString("dd-MMM-yyyy");
        //txtForDate.Text = Convert.ToDateTime(txtForDate.Text).ToString();
        //Convert.ToDateTime(
        //return;
        if (txtForDate.Text.ToString() == "")
        {
            lblErr.Text = "Enter the Activity date";
            return;
        }
        else
        {
            lblErr.Text = "";

        }
        ShowGriddata();
       
    }

 

    private String ServerSideMethod(String args)
    {
        ShowGriddata();
        form2 = form1;
        form2.Controls.Clear();
        form2.Controls.Add(GridView1);
        System.Text.StringBuilder sb = new System.Text.StringBuilder();
        HtmlTextWriter htWriter = new HtmlTextWriter(new System.IO.StringWriter(sb));
        form2.RenderControl(htWriter);
       
        string strRenderedHTML = sb.ToString();
        int startindex = strRenderedHTML.IndexOf("<table");
        if (startindex < 0)
        {
            startindex = 1;
        }
        int endindex = strRenderedHTML.IndexOf("</table>");
        int length = (endindex - startindex) + 8;
        strRenderedHTML = strRenderedHTML.Substring(startindex, length);
        return strRenderedHTML;
       
    }
    #region "Call back Registration"
    private void RegisterCallBackReference()
    {
        String callBack = Page.ClientScript.GetCallbackEventReference(this, "arg",
             "CallbackOnSucceeded", "context", "CallbackOnFailed", true);
        //String callBack = Page.ClientScript.GetCallbackEventReference(this, "arg",
        //   "", "context", "", true);
        String clientFunction = "function CallServer(arg, context){ "
                       + callBack + "; }";
        Page.ClientScript.RegisterClientScriptBlock(this.GetType(),
                "Call To Server", clientFunction, true);
       


    }
    #endregion


    #region ICallbackEventHandler Members
    String returnValue;
    string ICallbackEventHandler.GetCallbackResult()
    {
        return returnValue;
    }
   
   
    void ICallbackEventHandler.RaiseCallbackEvent(string eventArgument)
    {
        returnValue = ServerSideMethod(eventArgument);
    }


    #endregion
}