Tuesday, September 23, 2014

GridView textbox Navigation using Arrow(up/down) keys using Javascript in ASP.Net

 function GetTextBoxValues1(txt) {
//sai krishna for right arrow
//debugger;
if (window.event.keyCode == 39) {
    //var cnt = document.getElementById("GridView1").rows[0].cells.length;
    var gridView = document.getElementById("GridView1");
    for (var i = 1; i < gridView.rows.length - 1; i++) {
        if (txt == document.getElementById("GridView1_txtWeek1_" + (i - 1)).id) {
            document.getElementById("GridView1_txtweek2_" + (i - 1)).focus();
            return false;
        }
        if (txt == document.getElementById("GridView1_txtweek2_" + (i - 1)).id) {
            document.getElementById("GridView1_txtweek3_" + (i - 1)).focus();
            return false;
        }
        if (txt == document.getElementById("GridView1_txtweek3_" + (i - 1)).id) {
            document.getElementById("GridView1_txtweek4_" + (i - 1)).focus();
            return false;
        }
        if (txt == document.getElementById("GridView1_txtweek4_" + (i - 1)).id) {
            document.getElementById("GridView1_txtweek4_" + (i - 1)).focus();
            return false;
        }
                  
    }
}
//sai krishna for left arrow
//debugger;
if (window.event.keyCode == 37) {
    //var cnt = document.getElementById("GridView1").rows[0].cells.length;
    var gridView = document.getElementById("GridView1");
    for (var i = gridView.rows.length - 1; i >= 1 ; i--) {
        if (txt == document.getElementById("GridView1_txtWeek1_" + (i - 1)).id) {
            document.getElementById("GridView1_txtWeek1_" + (i-1)).focus();
            return false;
        }
        if (txt == document.getElementById("GridView1_txtweek2_" + (i - 1)).id) {
            document.getElementById("GridView1_txtWeek1_" + (i - 1)).focus();
            return false;
        }
        if (txt == document.getElementById("GridView1_txtweek3_" + (i - 1)).id) {
            document.getElementById("GridView1_txtweek2_" + (i - 1)).focus();
            return false;
        }
        if (txt == document.getElementById("GridView1_txtweek4_" + (i - 1)).id) {
            document.getElementById("GridView1_txtweek3_" + (i - 1)).focus();
            return false;
        }
    }
}
//sai krishna for down arrow
if (window.event.keyCode == 40) {
    var gridView = document.getElementById("GridView1");
    for (var i = 1; i < gridView.rows.length-1; i++) {
        if (txt == document.getElementById("GridView1_txtWeek1_" + (i - 1)).id)
        {
            document.getElementById("GridView1_txtWeek1_" + (i)).focus();
            return false;
        }
    }
    for (var i = 1; i < gridView.rows.length - 1; i++) {
        if (txt == document.getElementById("GridView1_txtweek2_" + (i - 1)).id) {
            document.getElementById("GridView1_txtweek2_" + (i)).focus();
            return false;
        }
    }
    for (var i = 1; i < gridView.rows.length - 1; i++) {
        if (txt == document.getElementById("GridView1_txtweek3_" + (i - 1)).id) {
            document.getElementById("GridView1_txtweek3_" + (i)).focus();
            return false;
        }
    }
    for (var i = 1; i < gridView.rows.length - 1; i++) {
        if (txt == document.getElementById("GridView1_txtweek4_" + (i - 1)).id) {
            document.getElementById("GridView1_txtweek4_" + (i)).focus();
            return false;
        }
    }
}
//sai krishna for UP arrow
if (window.event.keyCode == 38) {
    var gridView = document.getElementById("GridView1");
    for (var i = gridView.rows.length - 1; i > 1 ; i--) {
        if (txt == document.getElementById("GridView1_txtWeek1_" + (i - 1)).id) {
            document.getElementById("GridView1_txtWeek1_" + (i-2)).focus();
            return false;
        }
    }
    for (var i = gridView.rows.length - 1; i > 1 ; i--) {
        if (txt == document.getElementById("GridView1_txtweek2_" + (i - 1)).id) {
            document.getElementById("GridView1_txtweek2_" + (i - 2)).focus();
            return false;
        }
    }
    for (var i = gridView.rows.length - 1; i > 1 ; i--) {
        if (txt == document.getElementById("GridView1_txtweek3_" + (i - 1)).id) {
            document.getElementById("GridView1_txtweek3_" + (i - 2)).focus();
            return false;
        }
    }
    for (var i = gridView.rows.length - 1; i > 1 ; i--) {
        if (txt == document.getElementById("GridView1_txtweek4_" + (i - 1)).id) {
            document.getElementById("GridView1_txtweek4_" + (i - 2)).focus();
            return false;
        }
    }
}
}

<asp:GridView ID="GridView1" TabIndex="0" runat="server" Width="100%" GridLines="Horizontal">
  <Columns>
    <asp:TemplateField HeaderText="Week" ItemStyle-HorizontalAlign="Center" HeaderStyle-CssClass="datagridheaders" HeaderStyle-ForeColor="white">
    <ItemTemplate>
  <asp:TextBox ID="txtweek2" runat="server" Width="75px" onkeyup="return GetTextBoxValues1(this.id);" Columns="10"></asp:TextBox>
  </ItemTemplate>
  </asp:TemplateField>
 </Columns>
</asp:GridView>

Thursday, September 11, 2014

Search for a specific text in entire database

USE [AIRLINES]
GO

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROC [dbo].[SearchTables]
(
     @SearchStr nvarchar(100)
)
AS
BEGIN

DECLARE @Results TABLE(ColumnName nvarchar(370), ColumnValue nvarchar(3630))
SET NOCOUNT ON
DECLARE @TableName nvarchar(256), @ColumnName nvarchar(128), @SearchStr2
nvarchar(110)
SET  @TableName = ''
SET @SearchStr2 = QUOTENAME('%' + @SearchStr + '%','''')

WHILE @TableName IS NOT NULL
BEGIN
     SET @ColumnName = ''
     SET @TableName =
     (
         SELECT MIN(QUOTENAME(TABLE_SCHEMA) + '.' + QUOTENAME(TABLE_NAME))
         FROM    INFORMATION_SCHEMA.TABLES
         WHERE       TABLE_TYPE = 'BASE TABLE'
             AND QUOTENAME(TABLE_SCHEMA) + '.' + QUOTENAME(TABLE_NAME) > @TableName
             AND OBJECTPROPERTY(
                     OBJECT_ID(
                         QUOTENAME(TABLE_SCHEMA) + '.' +
QUOTENAME(TABLE_NAME)
                          ), 'IsMSShipped'
                            ) = 0
     )
     WHILE (@TableName IS NOT NULL) AND (@ColumnName IS NOT NULL)
     BEGIN
         SET @ColumnName =
         (
             SELECT MIN(QUOTENAME(COLUMN_NAME))
             FROM    INFORMATION_SCHEMA.COLUMNS
             WHERE       TABLE_SCHEMA    = PARSENAME(@TableName, 2)
                 AND TABLE_NAME  = PARSENAME(@TableName, 1)
                 AND DATA_TYPE IN ('char', 'varchar', 'nchar', 'nvarchar')
                 AND QUOTENAME(COLUMN_NAME) > @ColumnName
         )
         IF @ColumnName IS NOT NULL
         BEGIN
             INSERT INTO @Results
             EXEC
             (
                 'SELECT ''' + @TableName + '.' + @ColumnName + ''', LEFT(' + @ColumnName + ', 3630)
                 FROM ' + @TableName + ' (NOLOCK) ' +
                 ' WHERE ' + @ColumnName + ' LIKE ' + @SearchStr2
             )
         END
     END
END
SELECT ColumnName, ColumnValue FROM @Results END

--To execute the above Stored Procedure
DECLARE @return_value int
EXEC @return_value = [dbo].[SearchTables]
@SearchStr = N'SAIKRISHNA'
SELECT 'Return Value' = @return_value

Sunday, August 24, 2014

Get full path of the selected file using FileUpload1 control

string  fileName = Path.GetFullPath(FileUpload1.PostedFile.FileName);

Friday, May 9, 2014

Refresh the form automatically in MS CRM

Recently I faced a scenario where the page should load automatically I,e once the record has been created internally workflow will trigger [to update the telephone number in account] which will update the created record fields for this use the below code on onload 

function Refresh()
{
var type = Xrm.Page.ui.getFormType();
if(type==2)//form opened for update
{
var x=Xrm.Page.getAttribute("telephone1").getValue();
if(x==""||x==null)
{
setTimeout("doTimer()", 8000);//for 8 seconds
}
}
}

function doTimer()
{
window.location.reload(true);

}

CRM 2011: Custom Reports & the rsProcessingAborted Error

I created a custom report for CRM 2011 in BIDS , but it is throwing an error “The report cannot be displayed. (rsProcessingAborted)” message . Out-of-the-box reports would display fine.

Reporting Error:
The report cannot be displayed. (rsProcessingAborted)



Resolution: It was not having the permission to connect to the CRM Database.
1> I then opened my SQL.
2> Went to Security -> Logins
3> Right Click NT Authority\SYSTEM (in my case)
4> Selected user Mapping
5> Checked the MSSCRM_CONFIG and Org_MSCRM with roles of :
·         CRMReaderRole
·         public
·         db_ownwer


After this refresh the database to resolve this.

Thursday, May 8, 2014

Multi Select Look up in MS CRM 2011

First create three text fields in Opportunity as new_sguid, new_stype, new_sname

Add the below code in the Web Resource
function onchange() {
    var originatingLeadValue = Xrm.Page.getAttribute("originatingleadid").getValue();
    if (IsNull(originatingLeadValue) || originatingLeadValue[0].type == "4") {
        // Lookup is null or there is a Lead, need to clear hidden fields. To clear one of them will be enough, we will be check this field during onload.
        Xrm.Page.getAttribute("new_sguid").setValue(null);
    }
    else {
        // Lookup contains Contact or User, so need to store lookup properties to our hidden fields.
        Xrm.Page.getAttribute("new_stype").setValue(originatingLeadValue[0].type);
        Xrm.Page.getAttribute("new_sguid").setValue(originatingLeadValue[0].id);
        Xrm.Page.getAttribute("new_sname").setValue(originatingLeadValue[0].name);
    }
}

function onsave() {
    var originatingLeadValue = Xrm.Page.getAttribute("originatingleadid").getValue();
    if (!IsNull(originatingLeadValue) && originatingLeadValue[0].type != '4') {
        Xrm.Page.getAttribute("originatingleadid").setValue(null);
    }
}

function onload() {
    debugger;
    lookuptypeIcons = '/_imgs/ico_16_1.gif:/_imgs/ico_16_2.gif:/_imgs/ico_16_4.gif:/_imgs/ico_16_8.gif:/_imgs/ico_16_9.gif';//add the custom entity type gif image
    lookuptypenames = 'account:1:Account,contact:2:Contact,lead:4:Lead,systemuser:8:User,team:3:Team';
    lookuptypes = '1,2,4,8,9';// Here first one is entity name, the second one we can get by opening any record for our custom entity and check out the etc value in the url and the third one is the display name for your entity. And i used /_imgs/ico_16_customEntity.gif for the icons to work with.

    var savedId = Xrm.Page.getAttribute("new_sguid").getValue();
    var savedType = Xrm.Page.getAttribute("new_stype").getValue();
    var savedName = Xrm.Page.getAttribute("new_sname").getValue();
    var savedEntityName = savedType == "8" ? "systemuser" : "contact";
    document.getElementById("originatingleadid").setAttribute("lookuptypes", lookuptypes);
    document.getElementById("originatingleadid").setAttribute("lookuptypenames", lookuptypenames);
    document.getElementById("originatingleadid").setAttribute("lookuptypeIcons", lookuptypeIcons);
    document.getElementById("originatingleadid").setAttribute("defaulttype", "4"); // default type - Lead entity
    var originatingLeadValue = Xrm.Page.getAttribute("originatingleadid").getValue();
    if (IsNull(originatingLeadValue) && !IsNull(savedId)) {
        var value = new Array();
        value[0] = new Object();
        value[0].displayClass = "ms-crm-Lookup-Item";
        value[0].keyValues = new Object();
        value[0].values = new Object();
        value[0].onclick = "openlui()";
        value[0].id = savedId;
        value[0].entityType = savedEntityName;
        value[0].typename = savedEntityName;
        value[0].name = savedName;
        value[0].type = savedType;
        Xrm.Page.getAttribute("originatingleadid").setValue(value);
    }

}
call the onload function on Opportunity onload, onsave function on Opportunity onsave, onchange on Opportunity originating lead change :)

Friday, April 11, 2014

Make all the Fields Readonly in the CRM form 2011

var controls = Xrm.Page.ui.controls.get();
for (var i in controls){
var control = controls[i];
if (!control.getDisabled()){
control.setDisabled(true);
}}

No Default Value on Two Options Field Dynamics CRM 2011

function setTwoOptionNull(twoOption) {
    var isCreateForm = Xrm.Page.ui.getFormType() == 1;
    var twoOptionField = Xrm.Page.getAttribute(twoOption);
    var twoOptionValue = twoOptionField.getValue();
    if (isCreateForm) {
        twoOptionField.setValue(null); // set the value to null on create
        twoOptionField.setSubmitMode("always"); // required to store the null value
        document.getElementById("rad_" + twoOption + "1").onclick = function () { 
            if (twoOptionValue == false) {
                twoOptionField.setValue(true);
                twoOptionField.setValue(false);
            }
        }
    }
}

pass the value "new_acceptreject" as shown below

Monday, April 7, 2014

Split the String in Microsoft Dynamics CRM using Javascript

Add the below function in the onload of the lead form

function getMonth()
{
debugger;
var Day=Xrm.Page.getAttribute("createdon").getValue().toString().substring(0,3);
alert(Day);
//you will get the output as Tue
}

Now open an existing lead record then the alert will show the Day of the lead createdon.

Dynamics CRM 2013 Javascript

Enable/Disable Business Process stage field:
Xrm.Page.getControl(‘header_process_fieldname’).setDisabled(false);  //Enabled
Xrm.Page.getControl(‘header_process_fieldname’).setDisabled(true);  //Disabled
Show/Hide Business Process stage field:
Xrm.Page.getControl(‘header_process_fieldname’).setVisible(true);  //Show
Xrm.Page.getControl(‘header_process_fieldname’).setDisabled(false);  //Hide
Get Value/ Set Value Business Process stage field:
Xrm.Page.getControl(‘header_process_fieldname’).getAttribute().setValue(value);  //Set Value
Xrm.Page.getControl(‘header_process_fieldname’).getAttribute().getValue();  //Get Value
Set and Remove Notification on Business Process stage field:
Xrm.Page.getControl(‘header_process_fieldname’).setNotification(“Notification message”);  //Set Notification message
Xrm.Page.getControl(‘header_process_fieldname’).clearNotification(); // Clear Notification message
Set Required levels on Business Process stage field:
(Xrm.Page.getControl(‘header_process_fieldname).getAttribute()).setRequiredLevel(‘required’); //Required level
(Xrm.Page.getControl(‘header_process_fieldname).getAttribute()).setRequiredLevel(‘none’); //none level
(Xrm.Page.getControl(‘header_process_fieldname).getAttribute()).setRequiredLevel(‘recommended’); //Recommended level

Set field notification
Xrm.Page.getControl(fieldname).setNotification(“Notification message”);
Clear field notification
Xrm.Page.getControl(fieldname).clearNotification();
Set form notification
//First parameter is message, second is notification type, third is optional id parameter
Xrm.Page.ui.setFormNotification(‘Error! Message’,'ERROR’,’1′);
Xrm.Page.ui.setFormNotification(‘Warning!Message’,'WARNING’,’2′);
Xrm.Page.ui.setFormNotification(‘Information! Message’,'INFORMATION’,’3′);
Clear form notification
//Pass parameter id of notification which needs to be cleared
Xrm.Page.ui.clearFormNotification(’1′);

I noticed that currency field value on CRM forms were not accessible using Xrm.Page.getAttribute(“Currency field name”).getValue() and Xrm.Page.getAttribute(“Currency field name”).setValue(Value)
The resolution is in such cases is:
// To get currency field
Xrm.Page.data.entity.attributes.get(“Currency field name”).getValue();
// To set currency field
Xrm.Page.data.entity.attributes.get(“Currency field name”).setValue(Value);

Friday, March 28, 2014

Differences Between the SQL-based and Fetch-based Reports


Area
SQL-based Report
Data Provider
The <DataProvider> element value in the .rdl file is set to SQL. For example:
<DataProvider>SQL</DataProvider>
Report query
The query specified for retrieving data is in the <CommandText> sub-element under the<Query> element in the report definition (.rdl file) is a SQL query. For example, the query for retrieving all account names for a SQL-based report will be:
<CommandText>SELECT name FROM FilteredAccount;</CommandText>

Area
Fetch-based report
Data Provider
The <DataProvider> element value in the .rdl file is set to MSCRMFETCH. For example:
<DataProvider>MSCRMFETCH</DataProvider>
Report query
The query specified for retrieving data is in the <CommandText> sub-element under the <Query> 
element in the report definition (.rdl file) is a FetchXML query. For example, the query for retrieving
 all account names for a Fetch-based report will be:
<CommandText>&lt;fetch version="1.0" output-format="xml-platform" mapping="logical"&gt;
    &lt;entity name="account"&gt;
        &lt;attribute name="name" /&gt;
    &lt;/entity&gt;
&lt;/fetch&gt;</CommandText>

Tuesday, March 18, 2014

Get all the tables from the SQL database

SELECT TABLE_SCHEMA, TABLE_NAME, COLUMN_NAME, ORDINAL_POSITION, COLUMN_DEFAULT, DATA_TYPE, CHARACTER_MAXIMUM_LENGTH, 
NUMERIC_PRECISION, NUMERIC_PRECISION_RADIX, NUMERIC_SCALE, DATETIME_PRECISION FROM INFORMATION_SCHEMA.COLUMNS ORDER BY TABLE_NAME

Friday, January 31, 2014

Get the data from all the tables

USE AIRLINE --DB NAME
GO
DECLARE @COLUMNNAME AS VARCHAR(50) = 'PNAME' --THE NAME OF THE COLUMN ON WHICH YOU NEED TO PUT THE CRITERIA
DECLARE @CRITERIA AS VARCHAR(50) = 'CONVERT(DATE,' + @COLUMNNAME + ') >= ''20130225''' -- THE ACTUAL CRITERIA/WHERE CLAUSE OF THE QUERY

PRINT @COLUMNNAME
PRINT @CRITERIA

SELECT 
  'SELECT ''' + T.NAME + ''' AS  TABLENAME, * FROM ' + T.NAME + ' WHERE ' + @CRITERIA 
FROM 
  SYS.COLUMNS C
INNER JOIN SYS.TABLES T
  ON T.OBJECT_ID = C.OBJECT_ID   
WHERE 
  C.NAME = @COLUMNNAME

Last Execution Date Time of a Stored Procedure

USE Airline
GO

SELECT 
  O.NAME,
  PS.LAST_EXECUTION_TIME
FROM 
  SYS.DM_EXEC_PROCEDURE_STATS PS 
INNER JOIN SYS.OBJECTS O 
  ON O.[OBJECT_ID] = PS.[OBJECT_ID] 

To get a list of Databases that were backed-up and do not currently exist

SELECT
  DISTINCT B.DATABASE_NAME
FROM
  MSDB.DBO.BACKUPSET B
WHERE
  DB_ID(B.DATABASE_NAME) IS NULL

To get the List of all Databases which are not backed up till date

SELECT
  D.NAME [DB_NAME]
FROM
  MASTER.SYS.DATABASES D
LEFT JOIN MSDB.DBO.BACKUPSET B
  ON B.DATABASE_NAME = D.NAME
WHERE
  D.DATABASE_ID IS NULL

To get the List/History/Log of all the Successful Backups

SELECT 
  B.MACHINE_NAME,
  B.SERVER_NAME,
  B.DATABASE_NAME AS DBNAME,
  B.BACKUP_START_DATE,
  B.BACKUP_FINISH_DATE,
  CASE 
    WHEN B.[TYPE] = 'D' THEN 'DATABASE'
    WHEN B.[TYPE] = 'I' THEN 'DIFFERENTIAL DATABASE'
    WHEN B.[TYPE] = 'L' THEN 'LOG'
    WHEN B.[TYPE] = 'F' THEN 'FILE OR FILEGROUP'
    WHEN B.[TYPE] = 'G' THEN 'DIFFERENTIAL FILE'
    WHEN B.[TYPE] = 'P' THEN 'PARTIAL'
    WHEN B.[TYPE] = 'Q' THEN 'DIFFERENTIAL PARTIAL'
    ELSE B.[TYPE]
  END BACKUP_TYPE,    
  B.EXPIRATION_DATE,
  B.[USER_NAME],
  DATEDIFF(MINUTE,B.BACKUP_START_DATE ,B.BACKUP_FINISH_DATE) AS TOTAL_TIME_IN_MINUTE,
  B.RECOVERY_MODEL,
  B.BACKUP_SIZE/(1024 * 1024 * 1024) AS TOTAL_SIZE_GB,
  BF.PHYSICAL_DEVICE_NAME AS LOCATION
FROM 
  MSDB.DBO.BACKUPSET AS B
INNER JOIN MSDB.DBO.BACKUPMEDIAFAMILY AS BF
  ON B.MEDIA_SET_ID=BF.MEDIA_SET_ID
ORDER BY 
  B.BACKUP_START_DATE DESC
GO

To get a list of all successful Backups taken till date for a particular Database

DECLARE @DBNAME AS VARCHAR(100) = 'AIRLINE'--DATABASE NAME
SELECT 
  B.MACHINE_NAME,
  B.SERVER_NAME,
 B.DATABASE_NAME AS DBNAME,
  B.BACKUP_START_DATE,
  B.BACKUP_FINISH_DATE,
  CASE 
    WHEN B.[TYPE] = 'D' THEN 'DATABASE'
    WHEN B.[TYPE] = 'I' THEN 'DIFFERENTIAL DATABASE'
    WHEN B.[TYPE] = 'L' THEN 'LOG'
    WHEN B.[TYPE] = 'F' THEN 'FILE OR FILEGROUP'
    WHEN B.[TYPE] = 'G' THEN 'DIFFERENTIAL FILE'
    WHEN B.[TYPE] = 'P' THEN 'PARTIAL'
    WHEN B.[TYPE] = 'Q' THEN 'DIFFERENTIAL PARTIAL'
    ELSE B.[TYPE]
  END BACKUP_TYPE,
  B.EXPIRATION_DATE,
  B.[USER_NAME],
  DATEDIFF(MINUTE,B.BACKUP_START_DATE ,B.BACKUP_FINISH_DATE) AS TOTAL_TIME_IN_MINUTE,
  B.RECOVERY_MODEL,
  B.BACKUP_SIZE/(1024 * 1024 * 1024) AS TOTAL_SIZE_GB,
  BF.PHYSICAL_DEVICE_NAME AS LOCATION
FROM 
  MSDB.DBO.BACKUPSET AS B
INNER JOIN MSDB.DBO.BACKUPMEDIAFAMILY AS BF
 ON B.MEDIA_SET_ID=BF.MEDIA_SET_ID
WHERE
  B.DATABASE_NAME = @DBNAME  
ORDER BY 
  B.BACKUP_START_DATE DESC
GO

Thursday, January 30, 2014

Export to Excel with child grid in .Net

DataSet dsParent = new System.Data.DataSet();
            //export to excel with allow paging =false
            Response.Clear();
            //parent grid
            grvFetchJobPosting.AllowPaging = false;
            Response.Buffer = true;
            GridView gvrChild = new GridView();
            System.IO.StringWriter oStringWriter = new System.IO.StringWriter();
            System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);
            dsParent = (DataSet)Session["FetchVMSData"];
            grvFetchJobPosting.AllowPaging = false;
            grvFetchJobPosting.DataSource = dsParent.Tables[0];
            grvFetchJobPosting.DataBind();

            HtmlForm frm = new HtmlForm();
            foreach (GridViewRow gvr in grvFetchJobPosting.Rows)
            {
                if (gvr.RowType == DataControlRowType.DataRow)
                {
                    GridView GridView2 = (GridView)gvr.FindControl("grvVendorData");//child grid view
                    GridView2.AllowPaging = false;
                }
            }

            Response.ContentType = "application/vnd.ms-excel";
            Response.AddHeader("Content-Disposition", "attachment;filename=SalesReport.xls");
            //Response.Headers["Content-Disposition"] = "attachment;filename=DetailedRRFReport.xls";
            Response.Charset = "";
            this.EnableViewState = false;
            this.ClearControls(grvFetchJobPosting);
            grvFetchJobPosting.RenderControl(oHtmlTextWriter);

            grvFetchJobPosting.Parent.Controls.Add(frm);
            frm.Attributes["runat"] = "server";
            //frm.Controls.Add(FetchRRFDataGrid);
            frm.RenderControl(oHtmlTextWriter);

            Response.Write(oStringWriter.ToString());
            Response.End();
           

Create Dynamic Calender from SQL Query

DECLARE @Month AS INT 
 SET @Month=DatePart(Month,GETDATE()) --Set the MONTH for which you want to generate the Calendar.
DECLARE @Year AS INT 
 SET @Year=DatePart(YEAR,GETDATE()) --Set the YEAR for which you want to generate the Calendar.

DECLARE @StartDate AS DATETIME = CONVERT(VARCHAR,@Year) + RIGHT('0' + CONVERT(VARCHAR,@Month),2) + '01'
DECLARE @EndDate AS DATETIME = DATEADD(DAY,-1,DATEADD(MONTH,1,@StartDate));
WITH Dates AS (
  SELECT @StartDate Dt
  UNION ALL
  SELECT DATEADD(DAY,1,Dt) 
FROM  Dates 
  WHERE DATEADD(DAY,1,Dt) <= @EndDate),Details AS ( 
 SELECT 
DAY(Dt) CDay,
DATEPART(WK,Dt) CWeek,
MONTH(Dt) CMonth,
YEAR(Dt) CYear,
DATENAME(WEEKDAY,Dt) DOW,
Dt 
 FROM 
Dates
)

SELECT
  Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday
FROM
  (SELECT CWeek,DOW,CDay FROM Details) D
PIVOT
(
 MIN(CDay)
 FOR DOW IN (Sunday,Monday,Tuesday,Wednesday,Thursday,Friday,Saturday)
) AS PVT
ORDER BY CWeek