Thursday, April 14, 2011
Get FckEditor value using javascrip
>> var inst = FCKeditorAPI.GetInstance("description");
var html = inst.GetHTML();
where description is the name or id of fckeditor instansce
Wednesday, February 3, 2010
Find row index of gridview on RowCommand without CommandArgument
protected void grdtest1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "DeleteRow")
{
LinkButton gv = (LinkButton)e.CommandSource;
GridViewRow gvr = (GridViewRow)gv.Parent.Parent;
int rownum = gvr.RowIndex;
}
}
Friday, April 3, 2009
Bind multiple column value in row in gridview using asp.net(c#.net)

Problem: I want to bind more than one column value in row in gridview . I fetch the value from database in table format now I want to bind the five row value in a single row in grid like this....
Tuesday, March 24, 2009
Replace enter key value
from textbox using asp.net with c#.net and save in database
Actually the problem is when we enter the value in textbox and press enter key. value like this
this is dilip
web developer
it save in database but when fetch value from database its showing in same line like this: this is dilip web developer
solution: string txtvalue = mytextbox.Text.ToString().Replace("\r\n", "
");
and save it.
Because enter key value is \r\n . and now it will show as u entered text
Wednesday, March 18, 2009
Return last date of the current month using sql
Tuesday, March 17, 2009
How get month name,weekday name,year using sql
select datepart(dw,getdate()) as weekdaynumber
RETURN THE WEEKDAYNAME
select datename(dw,getdate()) as weekdayname
RETURN THE CURRENTDATENUMBER
select day(getdate()) as currentdatenumber
RETURN THE CURRENTDATE
select GETDATE() as currentdate
RETURN THE CURRENTYEAR
select year(getdate()) as currentyear
RETURN THE CURRENTMONTHNUMBER
select month(getdate()) as currenmonthnumber
RETURN THE CURRENTDATENUMBER
select day(getdate()) as currentddatenumber
RETURN THE MONTHNAME
select datename(mm,getdate()) as currentmonthname
Get 2nd(second) lowest sallery using sql
where Sallery_tbl is table name and usallery is column name
Sunday, January 11, 2009
Update Table value with case in Sql
Ex. table Gender_tbl and like this
id Gen_Name
1 Male
2 Male
3 Female
4 Femal
5 Male
no I have to update Gen_Name Male with M and Femal with F
solution:
UPDATE GENDER_TBL SET Gen_Name= (CASE WHEN (Gen_Name='Male') THEN 'M' WHEN (Gen_Name='Female') THEN 'F' else ' ' end)
Posted by Dilip Kumar
Return Multiple Column vaue in Single column with comma separated using Sql
I have table test2 and column name id and value like this
Id
1
2
3
4
5
6
..
and I want result like this 1,2,3,4,5,6,....
solution:
declare @a varchar(500)
set @a = ' '
select @a = @a + cast(id as varchar(20)) + ',' from test2
if len(@a)>1
set @a= left(@a,len(@a)-1)
select case @a when ' ' then '0' else @a end as id
Spacebar Check in TextBox Using Javascript
Solution:
Create A textbox with id txtname and a button id btntest and wite this function inside script tag.
function trim(string)
{
var a = string.replace(/^\s+/, '');
return a.replace(/\s+$/, '')
}
function TestTrim()
{
x = window.document.getElementById("txtname");
str="Please Enter User Name";
if (trim(x.value)=="")
{
alert(str);
x.select();
x.focus();
return false ;
}
}
And then call the function on c#(code behind page)
btntest.Attributes.Add("onclick", "return TestTrim();");
Wednesday, January 7, 2009
How can search column in database using sql
solution:-
use databasename
select it and execute and then write this query and execute it . it will give all the table in wich there will be the column name like you search.
select * from information_schema.columns where column_name like '%abc%'
Search the table from database using sql
Solution:- select * from information_schema.tables where table_name like '%abc%'
where abc is table name
Thursday, October 16, 2008
Convert Asp.net to Asp.net Ajax enabled website in Asp.net 2.0
This quation was very difficult for me change the simple website to Ajax enable website. Simply if we want to make ajax enabled website then select the Ajaxenabledwebsite from the Dashboard when click on file new and website. but if I din't this then I faced problem to convert this asp.net website to Ajax enabled website. its very simple
step1: add the ajaxcontrolltoolkit.dll in your application bin folder by add refrence.
step2: add the some line of code in web.config inside the
Friday, September 19, 2008
Disable or readonly the checkbox using javascipt
document.getElementById("ChkBoxName").disabled =false;
And for the Enable the checkbox using javascript
document.getElementById("ChkBoxName").disabled =true;
Check the column value if value is in string format with coma separated using Sql
solution:
select * from s
where
sid like '44,%' or sid like '%,44,%'
or sid like '%,44' or sid='44'
where sid is column name
this will only return the 44
Return Multi Row value in a single column with comma seprated
I want Return output like 1,2,3,4,5 using sql.
There is one table in which has column
id name
1 Dilip
2 Dinesh
3 Varun
4 Dhanpat
5 Renuka
solution:
declare @a varchar(500)
set @a = ' '
select @a = @a + cast(id as varchar(20)) + ',' from tablename
if len(@a)>1
set @a= left(@a,len(@a)-1)
select case @a when '' then '0' else @a end as id
Use case , becaue may be there is no any value in this table so it will retun o
Sunday, July 27, 2008
Factory patteren based code in C#.net
using System;
using System.Data;
using System.Configuration;
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 interface myinterface
{
int add(int x,int y);
//int mul(int w, int z);
}
public class class1 : myinterface
{
public int add(int a, int b)
{
int c = a + b;
return c;
}
}
public class class2 : myinterface
{
public int add(int j, int k)
{
int l = j * k;
return l;
}
}
class Factory
{
public myinterface GetObject(int type)
{
myinterface base1 = null;
switch (type)
{
case 1:
base1 = new class1();
break;
case 2:
base1 = new class2();
break;
}
return base1;
}
}
public partial class _Default : System.Web.UI.Page
{
Factory factory = new Factory();
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
myinterface mytest = factory.GetObject(1);
int result = mytest.add(Convert.ToInt32(TextBox1.Text.ToString()), Convert.ToInt32(TextBox2.Text.ToString()));
txtresult.Text = Convert.ToString(result);
}
protected void Button2_Click(object sender, EventArgs e)
{
myinterface multiply = factory.GetObject(2);
int multiplevalue = multiply.add(Convert.ToInt32(TextBox1.Text.ToString()), Convert.ToInt32(TextBox2.Text.ToString()));
txtmultiply.Text = Convert.ToString(multiplevalue);
}
}
Thursday, July 24, 2008
Regular Expression in dotnet
Regular expression examples for decimals input
Positive Integers — ^\d+$
Negative Integers — ^-\d+$
Integer — ^-{0,1}\d+$
Positive Number — ^\d*\.{0,1}\d+$
Negative Number — ^-\d*\.{0,1}\d+$
Positive Number or Negative Number - ^-{0,1}\d*\.{0,1}\d+$
Phone number — ^\+?[\d\s]{3,}$
Phone with code — ^\+?[\d\s]+\(?[\d\s]{10,}$
Year 1900-2099 — ^(19|20)[\d]{2,2}$
Date (dd mm yyyy, d/m/yyyy, etc.) — ^([1-9]|0[1-9]|[12][1-9]|3[01])\D([1-9]|0[1-9]|1[012])\D(19[0-9][0-9]|20[0-9][0-9])$
IP v4 — ^(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5])\.(\d|[1-9]\d|1\d\d|2[0-4]\d|25[0-5]){3}$
Regular expression examples for Alphabetic input
Personal Name — ^[\w\.\’]{2,}([\s][\w\.\’]{2,})+$
Username — ^[\w\d\_\.]{4,}$
Password at least 6 symbols — ^.{6,}$
Password or empty input — ^.{6,}$|^$
email — ^[\_]*([a-z0-9]+(\.|\_*)?)+@([a-z][a-z0-9\-]+(\.|\-*\.))+[a-z]{2,6}$
domain — ^([a-z][a-z0-9\-]+(\.|\-*\.))+[a-z]{2,6}$
Url — http://([\w-]+\.)+[\w-]+(/[\w- ./?%&=]*)?
Other regular expressions
Match no input — ^$
Match blank input — ^\s[\t]*$
Match New line — [\r\n]|$
Friday, July 18, 2008
How use trigger in sql
CREATE trigger [TRIGGER_Deletesubcategory] ON dbo.category
FOR delete
AS
declare @nmid int
select @nmid=sno from deleted
delete from subcategory where cat_id= @nmid
There will be two table one is category and second one is subcategory and the primery key of category table will be sno and the this will foreign key(cat_id) for subcategory table.
Friday, July 11, 2008
Image Thumbnail using C#.net
resizeimage(imagename); (where imagegname like- image1.jpg)
//this is the image control where you bind the image
img src='MakeThumbnail.aspx?file="imagename" &h=" + h + " &w=" + w + "' height="200" widht="200"
//Resize function (where width of the image will be fix and the hight of the image will be change according to height
public void resizeimage(string image)
{
System.Drawing.Image img;
try
{
string path = Server.MapPath("imagefolder/" + image);
img = System.Drawing.Image.FromFile(path);
}
catch
{
string path = Server.MapPath("imagefolder/no_img_avai.gif");
img = System.Drawing.Image.FromFile(path);
}
h = img.Height;
w = img.Width;
if (w >= 103)
{
int hei = h * 103;
int he = hei / w;
h = he;
w = 103;
}
else
{
int hei = h * 103;
int he = hei / w;
h = he;
}
}
//MAKE ONE ASPX FILE NAME MakeThumbnail.aspx
using System;
using System.IO;
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 MakeThumbnail : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
// get the file name -- fall800.jpg
string file = Request.QueryString["file"];
int w = Convert.ToInt32(Request.QueryString["w"]);
int h = Convert.ToInt32(Request.QueryString["h"]);
string filepath = Server.MapPath("imagefolder/" + file.ToString());
// create an image object, using the filename we just retrieved
System.Drawing.Image image = System.Drawing.Image.FromFile(filepath);
// create the actual thumbnail image
System.Drawing.Image thumbnailImage = image.GetThumbnailImage(w, h, new System.Drawing.Image.GetThumbnailImageAbort(ThumbnailCallback), IntPtr.Zero);
// make a memory stream to work with the image bytes
MemoryStream imageStream = new MemoryStream();
// put the image into the memory stream
thumbnailImage.Save(imageStream, System.Drawing.Imaging.ImageFormat.Jpeg);
// make byte array the same size as the image
byte[] imageContent = new Byte[imageStream.Length];
// rewind the memory stream
imageStream.Position = 0;
// load the byte array with the image
imageStream.Read(imageContent, 0, (int)imageStream.Length);
// return byte array to caller with image type
Response.ContentType = "image/jpeg";
Response.BinaryWrite(imageContent);
}
public bool ThumbnailCallback()
{
return true;
}
}
