Wednesday, 4 April 2012

How to Convert A DataSet and DataGrid into Html Table




Using sw As New StringWriter()
                Using htw As New HtmlTextWriter(sw)
                    ' instantiate a datagrid  
                    Dim dg As New DataGrid()
                    dg.DataSource = ds.Tables(0)
                    dg.HeaderStyle.BackColor = Drawing.Color.Gray
                    dg.HeaderStyle.Font.Name = "Tahoma"
                    dg.HeaderStyle.Font.Size = "12"
                    dg.HeaderStyle.ForeColor = Drawing.Color.White
                    dg.DataBind()

''--------------For Fourth Column Align Right

                    While ds.Tables(0).Rows.Count > j
                        dg.Items(j).Cells(4).HorizontalAlign = HorizontalAlign.Right
                        j = j + 1
                    End While
                    '''---------------------------------------------------
                    dg.RenderControl(htw)
                    srtMsg = sw.ToString()
                    srtMsg = srtMsg1 + "</br>" + srtMsg + "</br></br></br>" + srtMsg2
                    Response.Write(srtMsg)
                End Using
            End Using

No comments:

Post a Comment