Friday 29 July 2016

Jquery ui datepicker show month and year only on same page


// HTML

// only month and year
  <input name="month" id="datMonthYearFrom" />

// All

  <input name="month1" id="datMonthYearTo" />

// JS

$(function () {
     $("#datMonthYearFrom").datepicker({
                        changeMonth: true,
                        changeYear: true,
                        showButtonPanel: true,
                        dateFormat: "MM yy",
                        onClose: function (dateText, inst) {
                            $(this).datepicker('setDate', new Date(inst.selectedYear, inst.selectedMonth, 1));
                        }

                    }).focus(function () {
                        var thisCalendar = $(this);
                        $('.ui-datepicker-calendar').detach();
                    });           






////////////////////////////////////////// Second


$("#datMonthYearTo").datepicker({
                        changeMonth: true,
                        changeYear: true,
                        showButtonPanel: true,
                        dateFormat: "MM yy",
                        onClose: function (dateText, inst) {
                            $(this).datepicker('setDate', new Date(inst.selectedYear, inst.selectedMonth, 1));
                        }
                    });


});




Thursday 21 July 2016

Export Data table into excel using asp.net c#


// Copy an excel file on sever
-->> test.xlsx or test.xls


// Code in C#
protected void Export_DataTable_To_Excel(DataTable dtRecords)
    {
        string XlsPath = Server.MapPath(@"~/test.xlsx");
        string attachment = string.Empty;
        if (XlsPath.IndexOf("\\") != -1)
        {
            string[] strFileName = XlsPath.Split(new char[] { '\\' });
            attachment = "attachment; filename=" + strFileName[strFileName.Length - 1];
        }
        else
            attachment = "attachment; filename=" + XlsPath;
        try
        {
            Response.ClearContent();
            Response.AddHeader("content-disposition", attachment);
            Response.ContentType = "application/vnd.ms-excel";
            string tab = string.Empty;

            foreach (DataColumn datacol in dtRecords.Columns)
            {
                Response.Write(tab + datacol.ColumnName);
                tab = "\t";
            }
            Response.Write("\n");

            foreach (DataRow dr in dtRecords.Rows)
            {
                tab = "";
                for (int j = 0; j < dtRecords.Columns.Count; j++)
                {
                    Response.Write(tab + Convert.ToString(dr[j]));
                    tab = "\t";
                }

                Response.Write("\n");
            }
            Response.End();
        }
        catch (Exception ex)
        {
            //Response.Write(ex.Message);
        }
    }


Tuesday 19 July 2016

Asp.net Chart Control Settings

// Remove Background lines

Chart1.ChartAreas[0].AxisX.MajorGrid.Enabled = false;
Chart1.ChartAreas[0].AxisY.MajorGrid.Enabled = false;


// Colored Chart Y & X axis lines

Chart1.ChartAreas[0].AxisX.LineColor = System.Drawing.Color.Green;

Chart1.ChartAreas[0].AxisY.LineColor = System.Drawing.Color.Red;


// Change Background line colors

Chart1.ChartAreas[0].AxisX.MajorGrid.LineColor = Color.FromArgb(90, 200, 200, 200);

Chart1.ChartAreas[0].AxisY.MajorGrid.LineColor = Color.FromArgb(90, 200, 200, 200);


// Change Data Values Angle


Chart1.Series[i].SmartLabelStyle.Enabled = false;// Remove auto property first

Chart1.Series[i].LabelAngle = -89; // Can vary from -90 to 90;



// add white space in value label in chart

Chart1.Series[i].Label ="      #VALY";




Asp.net Chart Control Settings

// Remove Background lines

Chart1.ChartAreas[0].AxisX.MajorGrid.Enabled = false;
Chart1.ChartAreas[0].AxisY.MajorGrid.Enabled = false;


// Colored Chart Y & X axis lines

Chart1.ChartAreas[0].AxisX.LineColor = System.Drawing.Color.Green;

Chart1.ChartAreas[0].AxisY.LineColor = System.Drawing.Color.Red;


// Change Background line colors

Chart1.ChartAreas[0].AxisX.MajorGrid.LineColor = Color.FromArgb(90, 200, 200, 200);

Chart1.ChartAreas[0].AxisY.MajorGrid.LineColor = Color.FromArgb(90, 200, 200, 200);


// Change Data Values Angle


Chart1.Series[i].SmartLabelStyle.Enabled = false;// Remove auto property first

Chart1.Series[i].LabelAngle = -89; // Can vary from -90 to 90;



// add white space in value label in chart

Chart1.Series[i].Label ="      #VALY";




Asp.net Chart Control Settings

// Remove Background lines

Chart1.ChartAreas[0].AxisX.MajorGrid.Enabled = false;
Chart1.ChartAreas[0].AxisY.MajorGrid.Enabled = false;


// Colored Chart Y & X axis lines

Chart1.ChartAreas[0].AxisX.LineColor = System.Drawing.Color.Green;

Chart1.ChartAreas[0].AxisY.LineColor = System.Drawing.Color.Red;


// Change Background line colors

Chart1.ChartAreas[0].AxisX.MajorGrid.LineColor = Color.FromArgb(90, 200, 200, 200);

Chart1.ChartAreas[0].AxisY.MajorGrid.LineColor = Color.FromArgb(90, 200, 200, 200);


// Change Data Values Angle


Chart1.Series[i].SmartLabelStyle.Enabled = false;// Remove auto property first

Chart1.Series[i].LabelAngle = -89; // Can vary from -90 to 90;


// add white space in value label in chart

Chart1.Series[i].Label ="      #VALY";




Asp.net Chart Control Settings

// Remove Background lines

Chart1.ChartAreas[0].AxisX.MajorGrid.Enabled = false;
Chart1.ChartAreas[0].AxisY.MajorGrid.Enabled = false;


// Colored Chart Y & X axis lines

Chart1.ChartAreas[0].AxisX.LineColor = System.Drawing.Color.Green;

Chart1.ChartAreas[0].AxisY.LineColor = System.Drawing.Color.Red;


// Change Background line colors

Chart1.ChartAreas[0].AxisX.MajorGrid.LineColor = Color.FromArgb(90, 200, 200, 200);

Chart1.ChartAreas[0].AxisY.MajorGrid.LineColor = Color.FromArgb(90, 200, 200, 200);


// Change Data Values Angle

Chart1.Series[i].SmartLabelStyle.Enabled = false;// Remove auto property first

Chart1.Series[i].LabelAngle = -89; // Can vary from -90 to 90;

Sunday 17 July 2016

Converting Comma Separated Value to Rows and Vice Versa in SQL Server



Query 1: 
Using ->> COALESCE function
-----------------------------------------

DECLARE @temp VARCHAR(MAX)
SELECT @temp = COALESCE(@temp+', ' ,'') + '['+ ColumnName+']'
FROM [dbo].[mstCombobox_Twhere Flag=33 order by SNo
SELECT @temp

// Result  

[1], [2], [3], [4], [5], [6], [7], [8], [9], [10], [11], [12], [13], [14], [15], [16], [17], [18], [19], [20], [21], [22], [23], [24]

Query 2: 
Using without ->> COALESCE function
 ------------------------------------------------
DECLARE @temp VARCHAR(MAX)
SET @temp = ''
SELECT @temp = @temp + state + ', '
FROM [dbo].[mstCombobox_Twhere Flag=33 order by SNo
SELECT SUBSTRING(@temp, 0, LEN(@temp))

// Result  

[1], [2], [3], [4], [5], [6], [7], [8], [9], [10], [11], [12], [13], [14], [15], [16], [17], [18], [19], [20], [21], [22], [23], [24]


Query 3:
Using ->> FOR XML PATH
 ---------------------------------------------------
DECLARE @temp VARCHAR(MAX)
SET @temp = (SELECT ', ' + cast(s.state as varchar)
                      FROM [dbo].[mstCombobox_T] s where Flag=33 order by SNo
                      ORDER BY s.state
                     FOR XML PATH(''))

SELECT SUBSTRING(@temp, 2, 200000) AS state


// Result 

[1], [2], [3], [4], [5], [6], [7], [8], [9], [10], [11], [12], [13], [14], [15], [16], [17], [18], [19], [20], [21], [22], [23], [24]

Converting Comma Separated Value to Rows and Vice Versa in SQL Server



Query 1: 
Using ->> COALESCE function
-----------------------------------------

DECLARE @temp VARCHAR(MAX)
SELECT @temp = COALESCE(@temp+', ' ,'') + '['+ Columnname+ ']'
FROM [dbo].[mstCombobox_Twhere Flag=33 order by SNo
SELECT @temp

// Result  

[1], [2], [3], [4], [5], [6], [7], [8], [9], [10], [11], [12], [13], [14], [15], [16], [17], [18], [19], [20], [21], [22], [23], [24]

Query 2: 
Using without ->> COALESCE function
 ------------------------------------------------
DECLARE @temp VARCHAR(MAX)
SET @temp = ''
SELECT @temp = @temp + state + ', '
FROM [dbo].[mstCombobox_Twhere Flag=33 order by SNo
SELECT SUBSTRING(@temp, 0, LEN(@temp))

// Result  

[1], [2], [3], [4], [5], [6], [7], [8], [9], [10], [11], [12], [13], [14], [15], [16], [17], [18], [19], [20], [21], [22], [23], [24]


Query 3:
Using ->> FOR XML PATH
 ---------------------------------------------------
DECLARE @temp VARCHAR(MAX)
SET @temp = (SELECT ', ' + cast(s.state as varchar)
                      FROM [dbo].[mstCombobox_T] s where Flag=33 order by SNo
                      ORDER BY s.state
                     FOR XML PATH(''))

SELECT SUBSTRING(@temp, 2, 200000) AS state


// Result 

[1], [2], [3], [4], [5], [6], [7], [8], [9], [10], [11], [12], [13], [14], [15], [16], [17], [18], [19], [20], [21], [22], [23], [24]

Friday 8 July 2016

File uploader with single Button click using css


// HTML

<div class="file-upload sf-button" style="width: 85px; float: right">
                                                        <span>Browse...</span>
                                                        <asp:FileUpload runat="server" CssClass="upload" ID="Upload_Photo" Style="width: 85px;" />

                                                    </div>

//CSS

.file-upload {
position: relative;
overflow: hidden;
height: 30px;
background-color: #e1e1e1;
padding: 0px 5px;
font-size: 12px;
line-height: 19px;
}
.file-upload input.upload {
top: 0;
left: 0;
margin: 0;
cursor: pointer;
opacity: 0;
filter: alpha(opacity=0);
height: 25px;
position: absolute
font-size: 12px;
}

// result


Excel Sort values in ascending order using function TEXTJOIN

 Excel ::  Text ::  1,3,5,2,9,5,11 Result :: 1,2,3,5,5,9,11 Formula ::     TEXTJOIN ( ",",1,SORT(MID(SUBSTITUTE( A1 ,","...