void
radGridView1_CellEditorInitialized(object
sender, GridViewCellEventArgs e)
|
{
|
if (e.ColumnIndex == 1)
|
{
|
if (e.Column is GridViewTextBoxColumn)
|
{
|
((RadTextBoxEditorElement)((RadTextBoxEditor)this.radGridView1.ActiveEditor).EditorElement).MaxLength
= 100;
|
}
|
}
|
}
|
Search This Blog
Thursday, March 14, 2013
How to limit the text length in RadGridView cell
Etichete:
Telerik
Tuesday, March 12, 2013
Interface C#
C# > Types > Interface
Interfaces can contain:
An interface can't contain:
Example:
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
interface IAnimal
{
string Name { get; set; }
string Type { get; set; }
}
class Dog : IAnimal, IComparable
{
private string strName;
private string strType;
public Dog(string name)
{
this.Name = name;
}
public string Name
{
get { return strName; }
set { strName = value; }
}
public string Type
{
get { return strType; }
set { strType = value; }
}
public int CompareTo(object obj)
{
if (obj is IAnimal)
return this.Name.CompareTo((obj as IAnimal).Name);
return 0;
}
}
public Form1()
{
InitializeComponent();
}
Dog dog1 = new Dog("Dog1");
dog1.Type = "Carnivore";
}
}
}
An interface contains only the signatures of properties and methods.
The implementation of the methods is done in the class that implements the interface.Interfaces can contain:
- methods
- properties
- events
- indexers
An interface can't contain:
- constants
- fields
- operators
- instance constructors
- destructors
- types
Example:
using System;
using System.Collections.Generic;using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApplicationCS
{interface IAnimal
{
string Name { get; set; }
string Type { get; set; }
}
class Dog : IAnimal, IComparable
{
private string strName;
private string strType;
public Dog(string name)
{
this.Name = name;
}
public string Name
{
get { return strName; }
set { strName = value; }
}
public string Type
{
get { return strType; }
set { strType = value; }
}
public int CompareTo(object obj)
{
if (obj is IAnimal)
return this.Name.CompareTo((obj as IAnimal).Name);
return 0;
}
}
public partial class Form1 : Form
{public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{Dog dog1 = new Dog("Dog1");
dog1.Type = "Carnivore";
Dog dog2 = new Dog("Dog2");
dog2.Type = "Carnivore";
Dog dog3 = new Dog("Dog3");
dog3.Type = "Carnivore";
int x = dog1.CompareTo(dog2); // reurn -1
int y = dog1.CompareTo(dog3); // reurn 0}
}
}
Etichete:
c#
Friday, March 8, 2013
Find large tables size in SQL Server
SQL Server > Scripts
Microsoft SQL Server has two undocumented stored procedures that allow you to process through all tables in a database (sp_MSforeachtable), or all databases (sp_MSforeachdb).
sp_MSforeachtable
Example: Find tables size in SQL Server
(
tbl_name sysname ,
rows int,
reserved_size VARCHAR(50),
data_size VARCHAR(50),
index_size VARCHAR(50),
unused_size VARCHAR(50)
)
INSERT #tbl_size
EXEC sp_msforeachtable 'sp_spaceused ''?'''
select
*
from
#tbl_size
order by
CAST(REPLACE(data_size, ' KB', '') AS int) desc
drop table #tbl_size
Microsoft SQL Server has two undocumented stored procedures that allow you to process through all tables in a database (sp_MSforeachtable), or all databases (sp_MSforeachdb).
sp_MSforeachtable
Example: Find tables size in SQL Server
SET NOCOUNT ON
CREATE TABLE #tbl_size (
tbl_name sysname ,
rows int,
reserved_size VARCHAR(50),
data_size VARCHAR(50),
index_size VARCHAR(50),
unused_size VARCHAR(50)
)
INSERT #tbl_size
EXEC sp_msforeachtable 'sp_spaceused ''?'''
select
*
from
#tbl_size
order by
CAST(REPLACE(data_size, ' KB', '') AS int) desc
drop table #tbl_size
Etichete:
SQL Server
Concatenate rows from table into a single text string SQL Server
SQL Server > XML Data > FOR XML > Concatenate rows into text lines
create table #person
(
id int,
name nvarchar(50)
)
insert into #person(id, name)
values (1,'john')
insert into #person(id, name)
values (1,'smith')
insert into #person(id, name)
values (2,'laura')
insert into #person(id, name)
values (2,'stan')
2 laura
2 stan
substring((Select ','+ p1.name AS [text()] From #person p1 Where p1.id = p2.id
ORDER BY p1.id For XML PATH ('')),2, 1000) name
From #person p2
drop table #person
create table #person
(
id int,
name nvarchar(50)
)
insert into #person(id, name)
values (1,'john')
insert into #person(id, name)
values (1,'smith')
insert into #person(id, name)
values (2,'laura')
insert into #person(id, name)
values (2,'stan')
select * from #person
1 john
1 smith2 laura
2 stan
select distinct
p2.id, substring((Select ','+ p1.name AS [text()] From #person p1 Where p1.id = p2.id
ORDER BY p1.id For XML PATH ('')),2, 1000) name
From #person p2
1 john,smith
2 laura,standrop table #person
Etichete:
SQL Server
No cache ASP.NET
ASP.NET > HttpCachePolicy > SetCacheability
HttpCachePolicy.SetCacheability Method (HttpCacheability)
Sets the Cache-Control header to one of the values of HttpCacheability.
Example:
Set the Cache-Control header to no-cache.
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Etichete:
asp.net
Wednesday, March 6, 2013
Last date of the month SQL Server
EOMONTH returns the last day of the month that contains the specified date
SELECT EOMONTH(GETDATE())
For older editions ( < SQL Server 2012 )
SELECT CAST(DATEADD(d,-1,(DATEADD(mm,DATEDIFF(m,0,GETDATE())+1,0)))AS DATE)
Etichete:
SQL Server
Tuesday, March 5, 2013
ComVisibleAttribute C#
C# > InteropServices > ComVisible
ComVisible Attribute indicates that the managed type is visible to COM.
The default value is true.
Examples:
1. AssemblyInfo.cs
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
2.ComVisible in classes and methods
[ComVisible(false)] //the class and its members are invisible to COM
class ClassA
{
public ClassA()
{
}
//if you derive ClassB from ClassA and export ClassB to COM, ClassA Method1 become visible to COM
public int Method1()
{
return 0;
}
[ComVisible(false)] // Method2 is invisible to COM
public int Method2()
{
return 1;
}
}
ComVisible Attribute indicates that the managed type is visible to COM.
The default value is true.
Examples:
1. AssemblyInfo.cs
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
2.ComVisible in classes and methods
[ComVisible(false)] //the class and its members are invisible to COM
class ClassA
{
public ClassA()
{
}
//if you derive ClassB from ClassA and export ClassB to COM, ClassA Method1 become visible to COM
public int Method1()
{
return 0;
}
[ComVisible(false)] // Method2 is invisible to COM
public int Method2()
{
return 1;
}
}
Etichete:
c#
Subscribe to:
Posts (Atom)