Wednesday, December 26, 2012

Merge Particular column that is repeating in Gridview

Protected Sub GridView1_RowDataBound(sender As Object, e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound

     
        For rowIndex As Integer = GridView1.Rows.Count - 2 To 0 Step -1
            Dim gviewRow As GridViewRow = GridView1.Rows(rowIndex)
            Dim gviewPreviousRow As GridViewRow = GridView1.Rows(rowIndex + 1)
            Dim cellCount As Integer = 0//replace 0 with column index
            If gviewRow.Cells(cellCount).Text = gviewPreviousRow.Cells(cellCount).Text Then
                If gviewPreviousRow.Cells(cellCount).RowSpan < 2 Then
                    gviewRow.Cells(cellCount).RowSpan = 2
                Else
                    gviewRow.Cells(cellCount).RowSpan = gviewPreviousRow.Cells(cellCount).RowSpan + 1
                End If
                gviewPreviousRow.Cells(cellCount).Visible = False
            End If
        Next



    End Sub

Monday, December 17, 2012

Bind DropdownList using arraylist,hashtable,array

Binding with array List(vb) :

Dim AnimalArrayList as new ArrayList()
AnimalArrayList.Add("Dog")
AnimalArrayList.Add("Cat")
AnimalArrayList.Add("Elephant")
AnimalArrayList.Add("Lion")
AnimalArrayList.Add("Cat")
MyDropDownList.DataSource = AnimalArrayList
MyDropDownList.DataBind()


 Binding with Hashtable(c#)  :
Hashtable hTable = new Hashtable();

        hTable.Add("1", "Hashtable Item 1");

        hTable.Add("2", "Hashtable Item 2");

        hTable.Add("3", "Hashtable Item 3");

        hTable.Add("4", "Hashtable Item 4");



        dropHashtable.DataSource = hTable;

        dropHashtable.DataBind();
 Binding with Array(c#,vb)  :
int[] Hour = new int[24];
for (int i=0; i <=24, i++)
{
ddlHour.Items.add(Hour[i]);
}