Friday, June 10, 2011

Access UserControl from Page


Hi..
To perform some reparative operation in application, its preferred to use UserControls.
Not necessary to have same display and bindings at everyplace. In that case we need to set values or call methods or pass values accordingly.
Here I have tried to figure out three cases, Hope it is helpful.
  1. Pass Table to Usercontrol and Set dynamically value to Controls
  2. Set Properties of control
  3. Call Usercontrol's Methods

Monday, June 6, 2011

Set Default Value as Function to column of a Table

Hello,
Generally we need to set default value to particular column in Database Table like isActive is true, IsDeleted is false.
same way many times we set CreatedOn Date as CurrentDate and that is by query of insert GetDate().
Static Values :
Its very easy to set some static value as Default value for column and that is as follow :
Static

Functions :
Set Default Date for Createdon Field as Follow :
Date
User Defined Functions :
Set User Defined function as Default Value as follow:
In my case I am supposed to get Random Hexa Code for Color. so I Have created an User Defined function for that
CREATE FUNCTION [dbo].[GetRandomColorCode]
( 
)
RETURNS varchar(6)
AS
BEGIN
Declare @Color varchar(6)
 RETURN (SELECT MyNewID FROM dbo.MyNewID)
END

Now set the function in columns as follow :

UserDefined



If this do not allow us to set Default value try following query to set

ALTER TABLE dbo.Table_1 ADD CONSTRAINT
 DF_Table_1_ColorCode DEFAULT ([dbo].[GetRandomColorCode]()) FOR ColorCode
GO

All the best



Happy Coding..