Wednesday 29 June 2011

Remove Border from Gridview and DataGrid

GridView and DataGrid have default Function to Applie All the Rules: How We can Remove the All rules from the Gridview and How We can Remove Border from the Gridview and DataGrid.

 Following Error in Most of the Case :

 

Because  of All rules apply to Gridview and Datagrid Control. We have to Manually Remove the Border with Following Property.

 
And You can Define Attributes of Grid view Control :

    Grid.Attributes.Remove("rules");

Hope this article useful  to All.

Tuesday 28 June 2011

Update Panel Mode in Ajax

Here is the interesting point to Discuss with you about the Update Panel Mod. Hope Everybody Likes this.
  
There are two Mode of Update panel in Ajax. 







    Mode="Conditional' causes the updatepanel to update when one of three things happen:

    1) If a Control within the Update panel causes the actual Post back
    2) If a Trigger on the Update panel updates
    3) If someone calls "Update()" on the Update panel itself
    Otherwise, it won't update and refresh.  When it is set to always, however, it will always refresh.

    Friday 24 June 2011

    Cross Apply and Outer Apply

     I introduce one of feature of Sql server 2005 (Cross Apply and Outer Apply)  :
    • We are going to create one function which will return top row from Work order table  based on  workorderFormatId and row number.  
    • Now We can run following Query :
    • It will return on top 2 rows from  Workorderformate 1
    • select * from dbo.fn_GetMax_WorkorderNumber(1,2)
      Now We Closer Look of Cross Apply: 



       SELECT  p.WorkorderNumberFormat,
              p.WorkorderNumberSample,
              p.IsActive
      FROM    dbo.SC_SVL_Workorder AS p CROSS APPLY
           dbo.fn_GetMax_WorkorderNumber(p.WorkorderNumberFormatId, 2)
              
      WHERE   p.WorkorderNumberFormatId IN (1, 2, 3, 531, 706)
      ORDER BY p.WorkorderNumberFormatId ASC

      OUTER APPLY :


      SELECT  p.WorkorderNumberFormat,
              p.WorkorderNumberSample,
              p.IsActive
      FROM    dbo.SC_SVL_Workorder AS p OUTER APPLY
           dbo.fn_GetMax_WorkorderNumber(p.WorkorderNumberFormatId, 2)
              
      WHERE   p.WorkorderNumberFormatId IN (1, 2, 3, 531, 706)
      ORDER BY p.WorkorderNumberFormatId ASC
      •    As soon as you run above query, you will get 8 rows. Two rows for each workorderformateID (1,2,3,531). You will not get any row for workorderformateID 706 as it is not available in Workorder table.  This proves that CROSS APPLY clause works like INNER APPLY.  

      • you will get records for 706 WorkorderformatId IN Outer Apply Query


    Monday 13 June 2011

    SQL Charindex and PatIndex


    We can use either CHARINDEX or PATINDEX to search in TEXT field in SQL SERVER. The CHARINDEX and PATINDEX functions return the starting position of a pattern you specify.
        Its usefull tips. You can use both the things whenever required.
    Example of CHARINDEX:
    USE LIMS;
    GO
    SELECT CHARINDEX('ensure', DocumentSummary)
    FROM SC_Workorder
    WHERE DocumentID = 3;

    GO
    Examples of PATINDEX:

    USE LIMS;
    GO
    SELECT PATINDEX('%ensure%',DocumentSummary)
    FROM SC_Workorder
    WHERE DocumentID = 3;

    GO

    Friday 10 June 2011

    String.Contain Function in Asp.net

    This is the small But useful thing to remember. 

    We used to check whether a string object contains a specified string(text) using Index Of method.
    Here is the typical code to check the existence of a string in an string object. 


    //Sample code
    string sName = "Hello Nilay";
    if(sName.IndexOf("Nilay") > -1)
    {
         //Nilay exists in string object sName

    Now let's take a closer look at the above code...... What we want is to know whether an instance of string contains some string(text). 

    Did I say contains. that's exactly C# .Net 2.0 provides us with. 

    Let's revisit the same functionality using 2.0 

    //Sample code 
    string sName = "Hello Nilay";

    if(sName.Contains("Nilay"))
    {
         //Nilay exists in string object sName 
    }

    Friday 3 June 2011

    Replicate Function in Sql

    
    
    *    This is T-SQL Function and it repeats the string/character expression 
    N number of times specified in the function.
     
    //LIMS Database
    IF EXISTS(SELECT name FROM sys.tables WHERE name = 't1')
       DROP TABLE t1;
    GO
    CREATE TABLE t1 
    (
     c1 varchar(3),
     c2 char(3)
    );
    GO
    INSERT INTO t1 VALUES ('2', '2');
    INSERT INTO t1 VALUES ('37', '37');
    INSERT INTO t1 VALUES ('597', '597');
    GO
    SELECT REPLICATE('0', 3 - DATALENGTH(c1)) + c1 AS 'Varchar Column',
           REPLICATE('0', 3 - DATALENGTH(c2)) + c2 AS 'Char Column'
    FROM t1;
    GO


    Server Side Paging in SQL Server 2011 –Denali


    --Create By : Nilay Mistry
    --Date         : 02-Jun-2011

    DECLARE @RowsPerPage INT = 10,
    DECLARE @PageNumber INT = 5

    SELECT *
    FROM EmployeeMaster
    ORDER BY EmployeeID
    OFFSET
    @PageNumber*@RowsPerPage ROWS
    FETCH NEXT 10 ROWS ONLY
    GO