Pages

Sunday, October 16, 2011

How to select checkboxes in an ASP.NET CheckBoxList using jQuery

On click of Save button validate check box list any item checked or not
$(document).ready(function () {
        $("#<%= btnSave.ClientID%>").click(function () {
            var valid = false;
            var valid = $("[id^=<%= ckbDepertment.ClientID %>]:checkbox:checked").length > 0;

            if (valid) {
                return;
            }
            else {
                alert("Please select any deparment");
            }

            return valid;
        });
    });

Tuesday, September 20, 2011

Searching, sorting and paging in Oracle Store Procedure

create or replace PROCEDURE UP_GETSITEOWNERINFO
(
p_inStartRowIndex in number, p_inEndRowIndex in number,
p_vchSiteCode in VARCHAR2 :=null,
p_vchOwnerName in VARCHAR2 :=null,
p_vchCnic in VARCHAR2 :=null,
p_inSortExp in varchar2, p_outTotalRows out number,
p_cursor OUT sys_refcursor
)
AS
BEGIN
select count(*) into p_outTotalRows from SITE
           inner join SITE_OWNERS  on SITE_OWNERS.vchsitecode= SITE.VCHSITECODE
          inner join OWNER  on OWNER.INTOWNERID= Site_Owners.intownerid
where (p_vchSiteCode is null or SITE.vchsitecode like p_vchSiteCode)
and (p_vchcnic is null or vchcnic like p_vchcnic)
and (p_vchownername is null or
      vchfirstname like p_vchownername);


   open p_cursor for select * from
        (select SITE.vchsitecode,SITE.vchcity,SITE.vchdistrict,SITE.dtmdatecreated
        , OWNER.vchfirstname as OwnerName
        , OWNER.vchcnic
        , ROW_NUMBER()
        OVER
        (ORDER BY
          Decode(p_inSortExp,'VCHSITECODED Ascending',SITE.vchsitecode) ASC,
          Decode(p_inSortExp,'VCHSITECODE Descending',SITE.vchsitecode) DESC,
          Decode(p_inSortExp,'OWNERNAME Ascending',OWNER.vchfirstname) ASC,
          Decode(p_inSortExp,'OWNERNAME Descending',OWNER.vchfirstname) DESC,
          Decode(p_inSortExp,'VCHCNIC Ascending',OWNER.vchcnic) ASC,
          Decode(p_inSortExp,'VCHCNIC Descending',OWNER.vchcnic) DESC,
           SITE.vchsitecode)
           R from SITE
           inner join SITE_OWNERS  on SITE_OWNERS.vchsitecode= SITE.VCHSITECODE
          inner join OWNER  on OWNER.INTOWNERID= Site_Owners.intownerid
where (p_vchSiteCode is null or SITE.vchsitecode like p_vchSiteCode)
and (p_vchcnic is null or vchcnic like p_vchcnic)
and (p_vchownername is null or
      vchfirstname like p_vchownername)
        )
WHERE R BETWEEN ((p_inStartRowIndex - 1) * p_inEndRowIndex + 1) and (p_inStartRowIndex * p_inEndRowIndex) ;
END UP_GETSITEOWNERINFO;

Wednesday, September 1, 2010

Cross join Vs Loop in SQL

 Search different keywords in sql database through Cross join while using loop
 First run Create function code then execute the database query

// Create Function First
Create function [dbo].[fn_split](
@str varchar(max),
@delimiter char(1)
)
returns @returnTable table (idx int primary key identity, item varchar(8000))
as
begin
declare @pos int
select @str = @str + @delimiter

while len(@str) > 0
    begin
        select @pos = charindex(@delimiter,@str)
        if @pos = 1
            insert @returnTable (item)
                values (null)
        else
            insert @returnTable (item)
                values (substring(@str, 1, @pos-1))
        select @str = substring(@str, @pos+1, len(@str)-@pos)
      
    end
return
end



// Query part

DROP TABLE vTable3
DROP TABLE vTable1

CREATE TABLE vTable1 (id1 INT, NAME VARCHAR(100)Primary Key (id1))
CREATE TABLE vTable3 (id3 INT, id1 int, Deductions VARCHAR(100),Primary Key (id3),
Foreign Key (id1) references vTable1(id1))


INSERT INTO vTable1
    SELECT 1,'Shamas' union all
    select 5,'Qamar' UNION ALL
    SELECT 2,'Atif' UNION ALL
    SELECT 3,'Kashif' UNION ALL
    SELECT 4,'Imran'

INSERT INTO vTable3
    SELECT 1,2,'70' UNION ALL
    SELECT 2,5,'80'


DECLARE @vParam VARCHAR(100)
SET @vParam = '70,s'

SELECT distinct t1.*,t3.* FROM vTable1 t1
left Outer join vTable3 t3 on t3.id1=t1.id1
CROSS APPLY (SELECT item FROM dbo.[fn_split](@vParam,',')) b
WHERE
(t1.NAME LIKE '%' + b.item + '%'
  or t3.Deductions LIKE '%' + b.item + '%'
)

Thursday, July 15, 2010

Get Registered Version of Microsoft Products

Just log on http://www.asp.net
Create your account and get VS2010, SQL Server 2008 R2 and Windows Server 2008 R2 for 3 years

Wednesday, July 14, 2010

Regular Expression for Date

Regular Expression for date format MM/dd/yyyy

^([1-9]|0[1-9]|1[012])[/]([1-9]|0[1-9]|[12][0-9]|3[01])[/](19|20)\\d\\d$

Convert HTML To Text

Below code convert html code into text form and remove all tags related to html, script and style etc. Code remove all tags with the help of regular expressions so you don't need any parser for this, and its more efficient then any parser.

public static string ConvertHTMLtoText(string input)
    {
        input = Regex.Replace(input, @"<script.*?>[\s\S]*?</.*?script>", "");

        input = Regex.Replace(input, @"<style.*?>[\s\S]*?</.*?style>", "");

        input = Regex.Replace(input, @"(&lt;|&lt;/)( )*\w*&gt;", "");

        return input = Regex.Replace(input, @"<( )*([^>])*>", "");

    }