Friday, February 28, 2014

how to to get the particular column of a dataset returned in asp.net

some times when we are working with excel sheet data,
we might experience the changes in column names,
in that case we can simply use the following code to access the particular column of a returned dataset

VB.Net code

Dim ds As New DataSet
ds.Tables(0).Columns(0)
ds.Tables(0).Columns(1)
and so on..

how to add a column to a dataset returned in asp.net

some times we need to append some columns to retunred dataset,
in that case we can use the following code to work out.

VB.Net code

Dim ds As New DataSet
ds.Tables(0).Columns.Add("UploadBy")

Thursday, February 6, 2014

asp.net calender control - how to bind data to a calender control in asp.net

we can bind the data to a calender control using DayRender Event


VB.Net code

Protected Sub Calendar1_DayRender(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DayRenderEventArgs) Handles Calendar1.DayRender
        Dim nextDate As DateTime
        Dim hl As HyperLink

        Dim TblCell As TableCell = CType(e, DayRenderEventArgs).Cell
        TblCell.Height = CType(88, Web.UI.WebControls.Unit)
        TblCell.Width = CType(200, Web.UI.WebControls.Unit)

        Try
            If Not CType(Session("dsEvents"), DataSet) Is Nothing Then
                For Each dr As DataRow In CType(Session("dsEvents"), DataSet).Tables(0).Rows
                    nextDate = CType(dr("VisitationDate"), DateTime)
                    If Not e.Day.IsOtherMonth Then
                        If nextDate = e.Day.Date Then
                            hl = New HyperLink
                            If CType(dr("Branch"), String) <> "" Then
                                hl.Text = "
" & CType(dr("Branch"), String)
                            Else
                                hl.Text = "
" & CType(dr("Others"), String)
                            End If
                            hl.NavigateUrl = "ViewDetails.aspx?ID=" & CType(dr("Id"), String)
                            hl.ToolTip = "Click for details."
                            hl.Font.Bold = False
                            hl.ForeColor = System.Drawing.ColorTranslator.FromHtml("#24618E")
                            e.Cell.BackColor = Color.Azure
                            e.Cell.Controls.Add(hl)
                            e.Cell.Wrap = True
                        End If
                    End If
                Next
            End If
            e.Day.IsSelectable = False
        Catch ex As Exception
            Response.Write(ex.ToString())
        End Try
    End Sub