How to use a Table control to display data vertically

<asp:Table id=’Table1′ runat=’server’></asp:Table> VB.NET ’Populate the DataSet ds Dim dr As DataRow For Each dc In ds.Tables(0).Columns Dim trow As New TableRow() Dim tcellcolname As New TableCell() ’To Display the Column Names For Each dr In ds.Tables(0).Rows tcellcolname.Text = dc.ColumnName trow.BackColor = System.Drawing.Color.Beige tcellcolname.BackColor = System.Drawing.Color.AliceBlue ’Populate the TableCell with the Column Name tcellcolname.Controls.Add(New LiteralControl(dc.ColumnName.ToString)) Next trow.Cells.Add(tcellcolname) ’To Display the Column Data For Each dr In ds.Tables(0).Rows Dim tcellcoldata As New TableCell() ’Populate the TableCell with the Column Data tcellcoldata.Controls.Add(New LiteralControl(dr(dc.ColumnName).ToString)) trow.Cells.Add(tcellcoldata) Next Table1.Rows.Add(trow) Next C# //Populate the DataSet ds foreach(DataColumn dc in ds.Tables[0].Columns ) { TableRow trow = new TableRow(); TableCell tcellcolname = new TableCell() ; foreach(DataRow dr in ds.Tables[0].Rows ) { tcellcolname.Text = dc.ColumnName ; trow.BackColor = System.Drawing.Color.Beige ; tcellcolname.BackColor = System.Drawing.Color.AliceBlue ; //Populate the TableCell with the Column Name tcellcolname.Controls.Add(new LiteralControl(dc.ColumnName.ToString())) ; } trow.Cells.Add(tcellcolname) ; //To Display the Column Data foreach(DataRow dr in ds.Tables[0].Rows ) { TableCell tcellcoldata =new TableCell() ; //Populate the TableCell with the Column Data tcellcoldata.Controls.Add(new LiteralControl(dr[dc.ColumnName].ToString())) ; trow.Cells.Add(tcellcoldata); } Table1.Rows.Add(trow) ; }

How to create a table control dynamically to populate data

<asp:Table id=’Table1′ runat=’server’></asp:Table> VB.NET Dim mycn As SqlConnection Dim myda As SqlDataAdapter Dim ds As DataSet mycn = New SqlConnection(‘server = localhost;uid=sa;password=;database=northwind’) myda = New SqlDataAdapter(‘Select Employeeid, FirstName , LastName from employees’, mycn) ds = New DataSet myda.Fill(ds, ‘Employees’) Dim dc As DataColumn Dim dr As DataRow For Each dr In ds.Tables(0).Rows Dim trow As New TableRow For Each dc In ds.Tables(0).Columns Dim tcell As New TableCell tcell.Controls.Add(New LiteralControl(dr(dc.ColumnName).ToString)) trow.Cells.Add(tcell) Next Table1.Rows.Add(trow) Next C# SqlConnection mycn ; SqlDataAdapter myda ; DataSet ds ; mycn = new SqlConnection(‘server = localhost;uid=sa;password=;database=northwind’); myda = new SqlDataAdapter(‘Select Employeeid, FirstName , LastName from employees’, mycn); ds = new DataSet(); myda.Fill(ds, ‘Employees’); TableRow trow ; TableCell tcell; foreach (DataRow dr in ds.Tables[0].Rows) { trow = new TableRow (); foreach( DataColumn dc in ds.Tables[0].Columns) { tcell= new TableCell (); tcell.Controls.Add(new LiteralControl(dr[dc.ColumnName].ToString())); trow.Cells.Add(tcell); } Table1.Rows.Add(trow); }

How can I set the maximum and minimum value for RangeValidator based on two dates

<asp:textbox id=’TextBox1′ runat=’server’></asp:textbox> <asp:rangevalidator id=’RangeValidator1′ type=’Date’ controltovalidate=’TextBox1′ runat=’server’ errormessage=’Not in range’ /> <asp:button id=’Button1′ runat=’server’ text=’Button’></asp:button> VB.NET … Dim dtMinDate As DateTime Dim dtMaxDate As DateTime dtMinDate = Convert.ToDateTime(’04/25/04′) dtMaxDate = Convert.ToDateTime(’10/17/04′) RangeValidator1.MinimumValue = dtMinDate RangeValidator1.MaximumValue = dtMaxDate TextBox1.Text = dtMaxDate.ToShortDateString RangeValidator1.ErrorMessage = ‘Not in Range of ‘ & dtMinDate.ToShortDateString() & ‘ to ‘ & dtMaxDate.ToShortDateString() C# DateTime dtMinDate ; DateTime dtMaxDate ; dtMinDate = Convert.ToDateTime(’04/25/04′); dtMaxDate = Convert.ToDateTime(’10/17/04’); RangeValidator1.MinimumValue = dtMinDate.ToShortDateString () ; RangeValidator1.MaximumValue = dtMaxDate.ToShortDateString () ; TextBox1.Text = dtMaxDate.ToShortDateString(); RangeValidator1.ErrorMessage = ‘Not in Range of ‘ + dtMinDate.ToShortDateString() + ‘ to ‘ + dtMaxDate.ToShortDateString();

How to sort the DataGrid using an ArrayList as the DataSource

<asp:DataGrid AllowSorting =True OnSortCommand=’SortData’ id=’DataGrid1′ runat=’server’ EnableViewState=’false’></asp:DataGrid> VB.NET Private Sub Page_Load(sender As Object, e As System.EventArgs) ’ Put user code to initialize the page here Dim arrlist As New ArrayList() arrlist.Add(‘Tips’) arrlist.Add(‘Tricks’) arrlist.Add(‘Code’) arrlist.Add(‘Samples’) DataGrid1.DataSource = arrlist DataGrid1.DataBind() ViewState(‘AList’) = arrlist End Sub ’Page_Load Protected Sub SortData([source] As [Object], e As System.Web.UI.WebControls.DataGridSortCommandEventArgs) If ViewState(‘SortOrder’) Is Nothing Then SortAsc() Else If ViewState(‘SortOrder’).ToString() = ‘ ASC’ Then SortDesc() Else SortAsc() End If End If End Sub ’SortData Sub SortAsc() ViewState(‘SortOrder’) = ‘ ASC’ CType(ViewState(‘AList’), ArrayList).Sort() DataGrid1.DataSource = ViewState(‘AList’) DataGrid1.DataBind() ViewState(‘Sort’) = ‘DESC’ End Sub ’SortAsc Sub SortDesc() ViewState(‘SortOrder’) = ‘ DESC’ CType(ViewState(‘AList’), ArrayList).Sort() CType(ViewState(‘AList’), ArrayList).Reverse() DataGrid1.DataSource = ViewState(‘AList’) DataGrid1.DataBind() ViewState(‘Sort’) = ‘ASC’ End Sub ’SortDesc C# private void Page_Load(object sender, System.EventArgs e) { // Put user code to initialize the page here ArrayList arrlist = new ArrayList (); arrlist.Add (‘Tips’); arrlist.Add (‘Tricks’); arrlist.Add (‘Code’); arrlist.Add (‘Samples’); DataGrid1.DataSource = arrlist ; DataGrid1.DataBind (); ViewState[‘AList’] = arrlist ; } protected void SortData(Object source, System.Web.UI.WebControls.DataGridSortCommandEventArgs e ) { if (ViewState[‘SortOrder’] ==null) { SortAsc(); } else if (ViewState[‘SortOrder’].ToString () == ‘ ASC’ ) { SortDesc(); } else { SortAsc(); } } void SortAsc() { ViewState[‘SortOrder’] = ‘ ASC’; ((ArrayList)ViewState[‘AList’]).Sort (); DataGrid1.DataSource = ViewState[‘AList’]; DataGrid1.DataBind (); ViewState[‘Sort’]=’DESC’; } void SortDesc() { ViewState[‘SortOrder’] = ‘ DESC’; ((ArrayList)ViewState[‘AList’]).Sort (); ((ArrayList)ViewState[‘AList’]).Reverse (); DataGrid1.DataSource = ViewState[‘AList’]; DataGrid1.DataBind (); ViewState[‘Sort’]=’ASC’; }