Friday, June 15, 2012

Give an option of "All" in RadGrid PageSize Combo


To show all rows in RadGrid. I want to give an option of "All" in RadGrid
PageSize Combo. Like this:


Solution:
VB Code
Protected Sub RadGrid1_ItemCreated(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridItemEventArgs) Handles RadGrid1.ItemCreated
        If TypeOf e.Item Is GridPagerItem Then
            Dim combo As RadComboBox = TryCast(TryCast(e.Item, GridPagerItem).FindControl("PageSizeComboBox"), RadComboBox)

            ' The number of items shown when all is selected
            Dim allRowsCount As Integer = Integer.MaxValue

            ' Remove duplicates
            Dim duplicate As RadComboBoxItem = combo.Items.FindItemByValue(allRowsCount.ToString())
            If duplicate IsNot Nothing Then
                duplicate.Remove()
            End If

            ' Create a new item for showing all
            Dim item As New RadComboBoxItem("All", allRowsCount.ToString())
            item.Attributes.Add("ownerTableViewId", e.Item.OwnerTableView.ClientID)
           
combo.Items.Add(item)

            ' Set the current pagesize as the selected value
            combo.Items.FindItemByValue(RadGrid1.PageSize.ToString()).Selected = True
        End If
    End Sub

Thursday, June 14, 2012

Hashtable Vs Dictionary(of T,T)

I will prefer yo use Dictonary(of T,T)  instead of hastbale because it is type safe and second it will not cast object type  in to appropriate type so performance is better .

Hashtable:

Hashtable is non generic type collection from name space(system.collection)
by default it can contain  any type  means it accept system.object(every type reference or value type derived from system.object class).Hashtable store item in key /value pair. means value are stored in hashcode of key
"key Can't duplicate".

Module Module1

    Sub Main()
        Dim list As New Hashtable
        list.Add(1, "yousuf")
        list.Add(2, "ashar")
        list.Add("third", "captain jack sparrow")
        list.Add(4, "babosa")
        Console.WriteLine("value of key :third")
        Console.WriteLine(list("third"))
        Console.WriteLine("Is Captain Jack Sparrow still in black perl")
        Console.WriteLine(list.ContainsValue("captain jack sparrow"))
        Console.WriteLine("Keys and values In list")
        For Each itm As DictionaryEntry In list
            Console.WriteLine("key : {0} and has value {1}", itm.Key, itm.Value)
        Next
        Console.WriteLine("Keys In list")
        For Each ky As Object In list.Keys
            Console.WriteLine("key : {0} ", ky)
        Next
        Console.WriteLine("values In list")
        For Each vl As Object In list.Values
            Console.WriteLine("value : {0} ", vl)
        Next
        Console.ReadLine()
    End Sub

End Module

Out Put:


Dictonary(of T,T):
Dictonary(of T,T)  is  generic type collection from name space(system.collection.generic)
 it can contain a specific type means that its type safe so that you can't insert an integer and string in same list.
Dim lst As New Dictonary(of T,T)
where "T" can be integer ,string or any type.  if you will assign T as "Object" then it will work same as non generic type.Dictonary(of T,T)  store item in key /value pair. means value are stored in hashcode of key"key Can't duplicate".

Module Module1
    Sub Main()
        Dim list As New Dictionary(Of Integer, String)
        list.Add(1, "yousuf")
        list.Add(2, "ashar")
        list.Add(3, "captain jack sparrow")
        list.Add(4, "babosa")
        Console.WriteLine("value of key :3")
        Console.WriteLine(list(3))
        Console.WriteLine("Is Captain Jack Sparrow still in black perl")
        Console.WriteLine(list.ContainsValue("captain jack sparrow"))
        Console.WriteLine("Keys and values In list")
        For Each itm As KeyValuePair(Of Integer, String) In list
            Console.WriteLine("key : {0} and has value {1}", itm.Key, itm.Value)
        Next
        Console.WriteLine("Keys In list")
        For Each ky As Object In list.Keys
            Console.WriteLine("key : {0} ", ky)
        Next
        Console.WriteLine("values In list")
        For Each vl As Object In list.Values
            Console.WriteLine("value : {0} ", vl)
        Next
        Console.ReadLine()
    End Sub
End Module

Out Put:

Tuesday, June 12, 2012

Stack VS Stack(of T)


I will prefer yo use Stack(of T)  instead of Stack because it is type safe and second it will not cast object type  in to appropriate type so performance is better .

Stack:

Stack is non generic type collection from name space(system.collection)
by default it can contain  any type  means it accept system.object(every type reference or value type derived from system.object class). stack work on the principle of  LIFO(Last  in First Out) .

Module Module1

    Sub Main()
        Dim stk As New Stack
        stk.Push(1)
        stk.Push("Second")
        stk.Push(3)
        stk.Push("4th")
        Console.WriteLine("first in List")
        Console.WriteLine(stk.Peek)
        stk.Pop()
        Console.WriteLine("after deque first in List")
        Console.WriteLine(stk.Peek)
        Console.ReadLine()
    End Sub
End Module

Out Put:
first in List
4th
after deque first in List
3

Stack(of T):

Stack(of T)  is  generic type collection from name space(system.collection.generic)
 it can contain a specific type means that its type safe so that you can't insert an integer and string in same list.
Dim lst As New stack(of T)
where "T" can be integer ,string or any type.  if you will assign T as "Object" then it will work same as non generic type.Queue(of T)  work on the principle of  LIFO(Last  in First Out) .

Module Module1
    Sub Main()
        Dim stk As New Stack(Of Integer)
        stk.Push(1)
        stk.Push(2)
        stk.Push(3)
        stk.Push(4)
        Console.WriteLine("first in List")
        Console.WriteLine(stk.Peek)
        stk.Pop()
        Console.WriteLine("after deque first in List")
        Console.WriteLine(stk.Peek)
        Console.ReadLine()
    End Sub
End Module

Out Put:
first in List
4
after deque first in List
3

Monday, June 11, 2012

Queue VS Queue(of T)


I will prefer yo use Queue(of T)  instead of Queue because it is type safe and second it will not cast object type  in to appropriate type so performance is better.

Queue:

Queue is non generic type collection from name space(system.collection)
by default it can contain  any type  means it accept system.object(every type reference or value type derived from system.object class). Queue work on the principle of  FIFO(first in First Out) .it insert items like in array (one after other in sequence)
Module Module1
 Sub Main()
        Dim que As New Queue()
        que.Enqueue(1)
        que.Enqueue("Second")
        que.Enqueue(3)
        que.Enqueue("4th")
        Console.WriteLine("first in List")
        Console.WriteLine(que.Peek)
        que.Dequeue()
        Console.WriteLine("after deque first in List")
        Console.WriteLine(que.Peek)
        Console.ReadLine()
    End Sub
End Module


Out Put:

first in List
1
after deque first in List
Second

Queue(of T):

Queue(of T)  is  generic type collection from name space(system.collection.generic)
 it can contain a specific type means that its type safe so that you can't insert an integer and string in same list.
Dim lst As New Queue(of T)
where "T" can be integer ,string or any type.  if you will assign T as "Object" then it will work same as non generic type.Queue(of T) work on the principle of  FIFO(first in First Out) .it insert items like in array (one after other in sequence)

Module Module1

    Sub Main()
        Dim que As New Queue(Of Integer)
        que.Enqueue(1)
        que.Enqueue(2)
        que.Enqueue(3)
        que.Enqueue(4)
        Console.WriteLine("first in List")
        Console.WriteLine(que.Peek)
        que.Dequeue()
        Console.WriteLine("after deque first in List")
        Console.WriteLine(que.Peek)
        Console.ReadLine()
    End Sub
End Module

Out Put:

first in List
1
after deque first in List
2


I will prefer yo use Queue(of T)  instead of Queue because it is type safe and second it will not cast object type  in to appropriate type so performance is better .





Friday, June 8, 2012

Arraylist Vs List collection in VB.net

ArrayList:

arraylist is non generic type collection from name space (system.collection)
by default it can contain  any type  means it accept system.object (every type reference or value type derived from system.object class).
For Example:

Module Module1
    Sub Main()
        Dim lst As New ArrayList
        lst.Add("yousuf")
        lst.Add(2)
        Dim STR() As String = {"ashar", "kamran"}
        lst.AddRange(Str)
        For Each Obj As Object In lst
            Console.WriteLine(Obj)
        Next
        Console.ReadLine()
    End Sub

End Module

Out Put:
yousuf
2
ashar
kamran


LIST:

list is  generic type collection from name space(system.collection.generic)
 it can contain a specific type means that its type safe so that you can't insert an integer and string in same list.
Dim lst As New List(Of  T)
where "T" can be integer ,string or any type.  if you will assign T as "Object" then it will work same as non generic type.
For Example:

Module Module1
    Sub Main()
        Dim lst As New List(Of String)
        lst.Add("yousuf")
         Dim STR() As String = {"yasir", "kamran"}
        lst.AddRange(Str)
        For Each Obj As Object In lst
            Console.WriteLine(Obj)
        Next
        Console.ReadLine()
    End Sub

End Module

Out Put:
yousuf
ashar
kamran


I will prefer you to use List instead of arraylist because it is type safe and second it will not cast object type  in to appropriate type so performance is better .






 

Friday, June 1, 2012

How to apply css on RadDatePicker

Problem:

How to apply css on RadDatePicker? I am Applying css like that :

<telerik:RadDatePicker ID="RadDatePicker1" Runat="server" Culture="en-US"
CssClass="txt_box">
</telerik:RadDatePicker>

but is not working, it is giving me unwanted results.

Solution:

You should use "DateInput" tag in RadDatePicker. for example:

<telerik:RadDatePicker ID="RadDatePicker1" Runat="server" Culture="en-US">
       <DateInput CssClass="txt_box">
       </DateInput>

</telerik:RadDatePicker>