Tuesday, 30 December 2014

Gridview CheckBox checked and Unchecked With Javascript

1.) In Gridview   TemplateField

<asp:TemplateField HeaderStyle-Width="120px" HeaderStyle-HorizontalAlign="Center" >
                        <HeaderTemplate>
                            <asp:CheckBox runat="server" ID="chkAll" Text="Select All" />
                        </HeaderTemplate>
                        <ItemTemplate>
                            <asp:CheckBox ID="chkSelect" Runat="server" AutoPostBack="False"></asp:CheckBox>
                        </ItemTemplate>
                        <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" />
                        <HeaderStyle ForeColor="White" />
                    </asp:TemplateField>

2) Javascript for Check box

 <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
    $(document).ready(function () {
        $("#<%=gvInvoices.ClientID%> input[id*='chkSelect']:checkbox").click(function () {
            //Get number of checkboxes in list either checked or not checked
            var totalCheckboxes = $("#<%=gvInvoices.ClientID%> input[id*='chkSelect']:checkbox").size();
            //Get number of checked checkboxes in list
            var checkedCheckboxes = $("#<%=gvInvoices.ClientID%> input[id*='chkSelect']:checkbox:checked").size();
            //Check / Uncheck top checkbox if all the checked boxes in list are checked
            $("#<%=gvInvoices.ClientID%> input[id*='chkAll']:checkbox").attr('checked', totalCheckboxes == checkedCheckboxes);
        });

        $("#<%=gvInvoices.ClientID%> input[id*='chkAll']:checkbox").click(function () {
            //Check/uncheck all checkboxes in list according to main checkbox 
            $("#<%=gvInvoices.ClientID%> input[id*='chkSelect']:checkbox").attr('checked', $(this).is(':checked'));
        });
    });

</script>

Thursday, 27 November 2014

Database Related

Q !: Create A Split Function In databse

Ans:

GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[fnSplitString]') AND type in (N'FN', N'IF', N'TF', N'FS', N'FT'))
BEGIN
execute dbo.sp_executesql @statement = N'Create  FUNCTION [dbo].[fnSplitString]
(
 @RowData varchar(8000),
 @SplitOn nvarchar(5)
)  
RETURNS @RtnValue table 
(
 Id int identity(1,1),
 Data nvarchar(100)

AS  
BEGIN 
 Declare @Cnt int
 Set @Cnt = 1

 While (Charindex(@SplitOn,@RowData)>0)
 Begin
  Insert Into @RtnValue (data)
  Select 
   Data = ltrim(rtrim(Substring(@RowData,1,Charindex(@SplitOn,@RowData)-1)))

  Set @RowData = Substring(@RowData,Charindex(@SplitOn,@RowData)+1,len(@RowData))
  Set @Cnt = @Cnt + 1
 End

 Insert Into @RtnValue (data)
 Select Data = ltrim(rtrim(@RowData))

 Return
END'
END


2) In Query
select * from [dbo].[tblInvoice] where [InvoiceID] in (select Data from fnSplitString('203,202',','))


2) My favourite Is

GO
IF NOT EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[fun_Split]') AND type in (N'FN', N'IF', N'TF', N'FS', N'FT'))
BEGIN
execute dbo.sp_executesql @statement = N'CREATE function [dbo].[fun_Split]   
(
  @String varchar(8000),   
  @Delimiter char(1)  
) Returns @Results Table (Items varchar(8000))   
  
  
As      
Begin      
 Declare @Index int      
 Declare @Slice varchar(4000)      
  Select @Index = 1      
  If @String Is NULL Return      
  While @Index != 0      
  Begin      
   
  Select @Index = CharIndex(@Delimiter, @String)      
  If (@Index != 0)      
  Select @Slice = left(@String, @Index - 1)      
  else      
  Select @Slice = @String      
  
  Insert into @Results(Items) Values (@Slice)      
  Select @String = right(@String, Len(@String) - @Index)      
  If Len(@String) = 0 break      
  End      
Return      
End ' 

END

Ouery Wil Be
select * from [dbo].[tblInvoice] where [InvoiceID] in (select * from [dbo].[fun_Split]('203,202',','))

insert statment when not matches column name

insert into [dbo].[tblInvoice] (InvoiceID,Name
select  InvoiceID,'Mahesh' as Name from [dbo].[fun_Split]('203,202',','))

Column Name should be same if not then use as and create table same as above  table.



Thursday, 28 August 2014


custom paging in gridview

1. Using your favorite graphic editor (Photoshop), create four buttons that will serve as your icon for the First, Previous, Next and Last buttons.

2. Set your GridView control’s AllowPaging property to true.
3. Add a PagingTemplate inside your GridView and insert 4 ImageButton, 1 DropDownList and a Label controls which will serve as your First, Previous, Next, Last, Page No., and Page Picker of your pager.



Your pager should look like this when you render the page.



4. Add an OnDataBound Event to your GridView. This will render and populate your DropDownList (for page picker) and Label (for page count) controls. Implementation can look like this.




5. Next, we implement an OnSelectedIndexChanged on our DropDownList to go to the selected page when a selection is made from our dropdown.

6. In order for you arrow buttons to work. We must implement an OnCommand event of your buttons. Before that we have to specify a CommandArgument properties to each of our buttons.


7. Finally, the OnCommand event implementation.


Summary

Customizing your GridView pager gives you flexibility and fine grain control over your grid listing. Just don’t be afraid of exploring, experimenting and playing with it to achieve the desired functionalities that you want. Happy coding.





Wednesday, 27 August 2014

Custom Sorting

First Step: Create Aspx page

Second Step: Create Class file
Third Step: Behind the  code file of aspx page


Asp.Net Interview Qustion And Answers

Qus.1:  What is  OOP ?

Ans:-       The object oriented programming (OOP) is a programming model Programs are organized around object and data rather than action and logic. 


Qus:2  What is an Abstraction ?

Ans:-   Abstraction means to show only the necessary details to the clients of the object .
      Abstraction is the process of hiding the working style of an object, and showing the information of an object in understandable manner.

Qus:3  What is an Encapsulation ?

Ans:-   Encapsulation means hiding the internal details of an object, i.e. how an object does something.

Encapsulation prevents clients from seeing its inside view, where the behaviour of the abstraction is implemented.

Encapsulation is a technique used to protect the information in an object from the other object.

Hide the data for security such as making the variables as private, and expose the property to access the private data which would be public.
So, when you access the property you can validate the data and set it.

Qus:4  What is inheritance ?

Ans:-  When a class acquire the property of another class is known as inheritance.
Inheritance is process of object reusability.
For example, A Child acquire property of Parents.


Qus:5 What is Polymorphism ?

Ans: Polymorphism means one name many forms.
One function behaves different forms.
In other words, "Many forms of a single object is called Polymorphism."



fig 1.2