Posts

Showing posts from June, 2011

Access UserControl from Page

Image
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. Pass Table to Usercontrol and Set dynamically value to Controls Set Properties of control Call Usercontrol's Methods

Set Default Value as Function to column of a Table

Image
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 : Functions : Set Default Date for Createdon Field as Follow : 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 : 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 Al...