Tuesday, August 14, 2012

Trigger in sql server 2008 with example

CREATE TRIGGER [dbo].[Tri_TriggerName_History]
    ON [dbo].[Tbl_TableName]
    FOR INSERT, UPDATE, DELETE
AS
    IF (SELECT COUNT(*) FROM inserted) > 0
    BEGIN
        IF (SELECT COUNT(*) FROM deleted) > 0
        BEGIN
                        INSERT INTO [dbo].[ Tbl_TableName _HistryTable]
                        (                      
                        PlanID ,
                        SSNId,
                        CreatedBy    ,
                        CreatedDate,
                        UpdatedBy,
                        UpdatedDate,
                        Operation
                        )
    select PlanID,
                        SSNId,                        
                        CreatedBy  ,
                        CreatedDate,
                            'USER',
                            GETDATE(),
                            'DATA UPDATED' FROM DELETED
        END
        ELSE
        BEGIN
    INSERT INTO [dbo].[ Tbl_TableName _HistryTable ]
                        (
                                               
                                                PlanID,
                                                SSNId,                                               
                                                CreatedBy    ,
                                                CreatedDate,
                                                UpdatedBy,
                                                UpdatedDate,
                                                Operation
                        )
    select            PlanID   ,
                        SSNId,                      
                        CreatedBy     ,
                        CreatedDate,
                            'USER',
                            GETDATE(),
                            'DATA INSERTED' FROM INSERTED
        END
    END
  
GO



Monday, August 13, 2012

How to Uncheck CheckBoxList on Cancle button in C#.net

protected void btnCancel_Click(object sender, EventArgs e)
{          
   UncheckCheckBoxList();
}

public void UncheckCheckBoxList()
{
      Int32 Index = chkListDependents.SelectedIndex;
      while (Index != -1)
      {
           chkListDependents.Items[Index].Selected = false;
           Index = chkListDependents.SelectedIndex;
       }
}

Wednesday, August 8, 2012

Select the Cell values on mouseover in gridview row in asp.net.

OR

Edit row on mouseover in gridview in asp.net.
protected void gridViewName_OnRowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "Select")
            {
                int index = Convert.ToInt32(e.CommandArgument);
                string str1 = gridViewName.Rows[index].Cells[0].Text;
                string str2 = gridViewName.Rows[index].Cells[1].Text;
                TextboxName.Text = Convert.ToDateTime(str1).ToString("MM/dd/yyyy");
                TextboxName.Text = str2;
            }
        }


        protected override void Render(System.Web.UI.HtmlTextWriter writer)
        {
            foreach (GridViewRow row in gridViewName.Rows)
            {
                if (row.RowType == DataControlRowType.DataRow)
                {
                    row.Attributes["onmouseover"] = "this.style.cursor='hand';";
                    row.Attributes["onmouseout"] =
                       "this.style.textDecoration='none';";
                    row.Attributes["onclick"] =
                     ClientScript.GetPostBackClientHyperlink(gridViewName,
                        "Select$" + row.DataItemIndex, true);
                }
            }
            base.Render(writer);
    
    }