Comma Seperator In Sql Server

select SUBSTRING((select ‘,’ + State From State Where State.Cid = Country.Cid
For xml path(”)),2,1000) as statename, Country from Country

Above query generate State name with comma seperator : result as shown below

comma seperator value result

File Download Dialogbox With File Extention

Write below code on download button click event….
protected void btnDownload_Click(object sender, EventArgs e)
{
string imgPath = btnDownload.CommandArgument; // image path goes here…(virtual path)
System.IO.FileInfo file = new System.IO.FileInfo(Server.MapPath(imgPath));
if (file.Exists)
{
HttpContext.Current.Response.AddHeader(“Content-Disposition”, “attachment; filename=drawing”);
HttpContext.Current.Response.AddHeader(“Content-Length”, file.Length.ToString());
string strExtention = file.Extension.ToString();
//HttpContext.Current.Response.ContentType = “application/octet-stream”;
HttpContext.Current.Response.ContentType = strExtention;
HttpContext.Current.Response.WriteFile(file.FullName);
HttpContext.Current.Response.End();
}
else
{
lblError.Text = “File Does Not Exits.”;
}
}

Upload images in FCKEDITOR in asp.net

1) Create a folder in root namely ” userfiles ” and inside it create sub folder ” image “. So its like this
userfiles \ image

2) Now edit the following lines in fckeditor\fckconfig.js file

var _FileBrowserLanguage = ‘php’ ; // asp | aspx | cfm | lasso | perl | php | py
var _QuickUploadLanguage = ‘php’ ; // asp | aspx | cfm | lasso | perl | php | py

Change it to following :-

var _FileBrowserLanguage = ‘aspx’ ; // asp | aspx | cfm | lasso | perl | php | py
var _QuickUploadLanguage = ‘aspx’ ; // asp | aspx | cfm | lasso | perl | php | py

3) Now edit the following lines in fckeditor\editor\filemanager\connectors\aspx\config.ascx

// URL path to user files.

UserFilesPath = “/userfiles/”;

Change to :-

UserFilesPath = “~/userfiles/”;

Now you are ready to use fckeditor.
Note :- That is for development on localhost. On remote sever don’t forget to give read/write permission to this userfiles and image folder.

SQL split function

DECLARE @str as varchar(max)
SET @str = ‘Prakash,Sanket,Jigar,JD’
SELECT value as GiveColumName from dbo.split(@str,’,’)

Split function used to insert to multiple records into tables…. see below procedure

INSERT INTO BoqThermoDrawing
SELECT @BoqNo,@RevisionNo,@RootPath+’\’+value from dbo.Split(@FileNames,’/’)

—————————————————————–
Create function in sql server… split after that u can use above function

USE [DataBaseName]
GO
/****** Object: UserDefinedFunction [dbo].[Split] Script Date: 03/04/2010 11:55:40 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

ALTER function [dbo].[Split](
@String nvarchar (4000),
@Delimiter nvarchar (10)
)
returns @ValueTable table ([ID] int,[Value] nvarchar(4000))
begin
declare @NextString nvarchar(4000)
declare @Pos int
declare @NextPos int
declare @CommaCheck nvarchar(1)

–Initialize
set @NextString = ”
set @CommaCheck = right(@String,1)

–Check for trailing Comma, if not exists, INSERT
–if (@CommaCheck @Delimiter )
set @String = @String + @Delimiter

–Get position of first Comma
set @Pos = charindex(@Delimiter,@String)
set @NextPos = 1

–Loop while there is still a comma in the String of levels
Declare @sr as int
set @sr =0
while (@pos 0)
begin
set @NextString = substring(@String,1,@Pos – 1)
set @sr = @sr + 1
insert into @ValueTable ([id], [Value]) Values (@sr , @NextString)

set @String = substring(@String,@pos +1,len(@String))

set @NextPos = @Pos
set @pos = charindex(@Delimiter,@String)
end

return
end

Open Aspx Page in Popup

Add this function in Search Page or View All items page..

function ShowPopUp(Id)
{
$get(”).src=”AssignTool.aspx?ID=”+Id;
$find(”).show();
document.getElementById(“”).innerHTML = “Assign Tool”;
return false;
}

—————– View All Items page ———–

 

——————— view All cs page coding —————

Gridview Row DataBound Event

if (e.Row.RowType == DataControlRowType.DataRow)
{
Button btnAccept = (Button)e.Row.Cells[16].Controls[0];
btnAccept.Attributes.Add(“onclick”, “return ShowPopUpAccept(” + rowView[“AssignToolId”].ToString() + “)”);
}

Date Comparision Javascript Validation

function ValidateDate()
{
var str1 = document.getElementById(“”).value;
var str2 = document.getElementById(“”).value;

var dt1 = parseInt(str1.substring(0,2),10);
var mon1 = parseInt(str1.substring(3,5),10);
var yr1 = parseInt(str1.substring(6,10),10);
var dt2 = parseInt(str2.substring(0,2),10);
var mon2 = parseInt(str2.substring(3,5),10);
var yr2 = parseInt(str2.substring(6,10),10);
var date1 = new Date(yr1, mon1, dt1);
var date2 = new Date(yr2, mon2, dt2);

if(date2 < date1)
{
alert("To date cannot be greater than from date");
return false;
}
return true;
}

Find Master Page Control In Content Page

  • Home
  • News

If I have understood this correctly…

If your list is on the master page…

  • Home
  • News

…then you can do this on your content page…

Control list = this.Page.Master.FindControl(“list”);

Then the li objects will be controls in the list object – e.g. list.Controls. Or you can do…

Control home = this.Page.Master.FindControl(“list”).FindControl(“home”);

…to find specific controls of the list control.

When using the runat=”server” on the HTML controls the server side equivalent object will be HtmlGenericControl.

If you want to apply a class to the LI tags what you would have to do is cast the LI object to a HtmlGenericControl and then use the Attributes property. For example…

HtmlGenericControl home = (HtmlGenericControl)this.Page.Master.FindControl(“list”).FindControl(“home”);

home.Attributes[“class”] = “className”;

Javascript Validation in Gridview

Make function in “Java Script” as Below… grvPowderCoat is Gridview ID

function PowderCoatValidate()
{
var result=””;
var GrvTst = document.getElementById(GetClientId(“grvPowderCoat”));
if (GrvTst != null) {

var Inputs = GrvTst.getElementsByTagName(“input”);
for (i = 0; i < Inputs.length; i++)
{
if (Inputs[i].type == 'text') {
var test1 = Inputs[i].id;
var array1 = test1.split("_");
if (array1[array1.length-1] == 'txtPowderA') {

if (Inputs[i].value == "")
{
result += "- Enter A\n";
//alert("Enter Width ");
//return false;
}
if(isNaN(Inputs[i].value))
{
result+= "- Enter Valid A\n";
}
}
if (array1[array1.length-1] == 'txtPowderValue') {

if (Inputs[i].value == "")
{
result += "- Enter Total\n";
}
if(isNaN(Inputs[i].value))
{
result+= "- Enter Valid Total\n";
}
}
}
}
var DDL = GrvTst.getElementsByTagName("select");
for (i = 0; i < DDL.length; i++)
{
if (DDL[i].type == 'select-one')
{
var test1 = DDL[i].id;
var array1 = test1.split("_");
if (array1[array1.length-1] == 'ddlPowderId')
{
if (DDL[i].selectedIndex == 0)
{
result += "- Select Section\n";
}
}
}
}
if(result!="")
{
alert(result);
return false;
}
}
}

Call this function in .CS Page

protected void grvPowderCoat_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow && (e.Row.RowState ==
DataControlRowState.Normal || e.Row.RowState == DataControlRowState.Alternate))
{
if (e.Row.RowType == DataControlRowType.DataRow) //check for RowType
{
string id = e.Row.Cells[0].Text; // Get the id to be deleted
LinkButton lb = (LinkButton)e.Row.Cells[0].Controls[2]; //cast the ShowDeleteButton link to linkbutton
if (lb != null)
{
lb.Attributes.Add(“onclick”, “return ConfirmOnDelete(‘” + id + “‘);”); //attach the JavaScript function with the ID as the paramter
}
}
}
if ((e.Row.RowState == (DataControlRowState.Edit | DataControlRowState.Alternate)) || (e.Row.RowState == DataControlRowState.Edit))
{
if (e.Row.RowType == DataControlRowType.DataRow) //check for RowType
{
string id = e.Row.Cells[0].Text; // Get the id to be deleted
LinkButton lb = (LinkButton)e.Row.Cells[0].Controls[0]; //cast the ShowDeleteButton link to linkbutton
if (lb != null)
{
lb.Attributes.Add(“onclick”, “return PowderCoatUpdate();”); //attach the JavaScript function with the ID as the paramter
}
}
}
}

Enalbe Or Disable Controls In Asp.Net

Give ID and runat=”server” attribute to Div or Table Tag for enable or disable the controls in it. Write the followin function and call them on any event.

Disable Controls

private void DisableControls(Control parent)
{
foreach (Control _ChildControl in parent.Controls)
{
if ((_ChildControl.Controls.Count > 0))
{
DisableControls(_ChildControl);
}
else
{
if (_ChildControl is TextBox)
{
((TextBox)_ChildControl).Enabled = false;
}
else
if (_ChildControl is CheckBox)
{
((CheckBox)_ChildControl).Enabled = false;
}
if (_ChildControl is DropDownList)
{
((DropDownList)_ChildControl).Enabled = false;
}
if (_ChildControl is RadioButton)
{
((RadioButton)_ChildControl).Enabled = false;
}
if (_ChildControl is GridView)
{

((GridView)_ChildControl).Enabled = false;
}
if (_ChildControl is LinkButton)
{
((LinkButton)_ChildControl).Enabled = false;
}
}
}
}
Enable Contorls
private void EnableControls(Control parent)
{
foreach (Control _ChildControl in parent.Controls)
{
if ((_ChildControl.Controls.Count > 0))
{
EnableControls(_ChildControl);
}
else
{
if (_ChildControl is TextBox)
{
((TextBox)_ChildControl).Enabled = true;
}
else
if (_ChildControl is CheckBox)
{
((CheckBox)_ChildControl).Enabled = true;
}
if (_ChildControl is DropDownList)
{
((DropDownList)_ChildControl).Enabled = true;
}
if (_ChildControl is RadioButton)
{
((RadioButton)_ChildControl).Enabled = true;
}
if (_ChildControl is GridView)
{
((GridView)_ChildControl).Enabled = true;
}
if (_ChildControl is LinkButton)
{
((LinkButton)_ChildControl).Enabled = true;
}
}
}

}
#endregion

#region “Update and Get Boq Approve details”
public void UpdateApproveByName()
{
dtSky = (DataTable)ViewState[“dtSky”];
SortedList sl = new SortedList();
sl.Add(“@ApproveBy”, txtApprovedName.Text);
sl.Add(“@ApproveDate”, DateTime.Today.ToShortDateString());
sl.Add(“@BoqNo”, Convert.ToString(dtSky.Rows[0][“BoqNo”]));

int rowAffected = obj.ExecuteSQL(“spUpdateBoq”, sl);
}

public void GetApproveDetails()
{
if (!string.IsNullOrEmpty(Request.QueryString[“BoqNo”]))
{
DataTable dtBoq = new DataTable();
SortedList sl = new SortedList();
sl.Add(“@BoqNo”,Convert.ToString(Request.QueryString[“BoqNo”]));
dtBoq = obj.GetDataTable(“spGetBoqId”,sl);
if (dtBoq != null)
{
if (dtBoq.Rows.Count > 0)
{
txtApprovedName.Text = Convert.ToString(dtBoq.Rows[0][“ApproveBy”]);
if (dtBoq.Rows[0][“ApproveDate”] != null)
{
lblApproveDateVal.Text = Convert.ToString(dtBoq.Rows[0][“ApproveDate”]);
}
}
}
}
}