How to set the background color of a web page using code behind?
Yes In the body tag, add runat=’server’ and give the tag an id (e.g. id=’bodyID’). In the class definition in the code-behind, add VB.NET Protected bodyID As System.Web.UI.HtmlControls.HtmlGenericControl C# protected System.Web.UI.HtmlControls.HtmlGenericControl bodyID ; In code, use the attributes collection to set the bgcolor attribute: VB.NET bodyID.Attributes.Add(‘bgcolor’, ‘green’) C# bodyID.Attributes.Add(‘bgcolor’, ‘green’);
How to loop through a Dataset to display all records
VB.NET ’Fill Dataset Dim dc As DataColumn Dim dr As DataRow For Each dr In ds.Tables(0).Rows For Each dc In ds.Tables(0).Columns Response.Write(dr(dc.ColumnName).ToString()) Next Next C# //Fill the DataSet foreach (DataRow dr in ds.Tables[0].Rows) { foreach( DataColumn dc in ds.Tables[0].Columns) { Response.Write(dr[dc.ColumnName].ToString()); } }
How to display errors using Page_Error event of Page Object
VB.NET Private Sub Page_Error(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Error Response.Write(Server.GetLastError().ToString) Server.ClearError() End Sub C# //In InitializeComponent this.Error += new System.EventHandler (this.Page_Error ); // private void Page_Error(object sender, System.EventArgs e ) { Response.Write(Server.GetLastError().ToString()); Server.ClearError (); } In the Same manner handle the Errors in the Application_Error event in global.asax
How to use OleDb DataReader
VB.NET Dim strConn As String = ‘Provider=Microsoft.Jet.OLEDB.4.0;Data Source=’ + Server.MapPath(‘nwind.mdb’) & ‘;’ Dim strsql As String = ‘Select * from Customers’ Dim cn As New OleDbConnection(strConn) Dim cmd As New OleDbCommand(strsql, cn) cn.Open() Dim dr As OleDbDataReader = cmd.ExecuteReader(CommandBehavior.CloseConnection) DataGrid1.DataSource = dr DataGrid1.DataBind() C# string strConn = ‘Provider=Microsoft.Jet.OLEDB.4.0;Data Source=’ + Server.MapPath(‘nwind.mdb’) + ‘;’; string strsql = ‘Select * from Customers’; OleDbConnection cn = new OleDbConnection(strConn); OleDbCommand cmd = new OleDbCommand (strsql, cn); cn.Open (); OleDbDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection ); DataGrid1.DataSource = dr; DataGrid1.DataBind();
How to use OleDb DataSet
Use namespace System.Data.OleDb VB.NET Dim strConn As String = ‘Provider=Microsoft.Jet.OLEDB.4.0;Data Source=’ + Server.MapPath(‘nwind.mdb’) & ‘;’ Dim strsql As String = ‘Select * from Customers’ Dim cn As New OleDbConnection(strConn) Dim ds As DataSet = New DataSet() Dim da As New OleDbDataAdapter(strsql, cn) da.Fill(ds, ‘T1’) DataGrid1.DataSource = ds DataGrid1.DataBind() C# string strConn = ‘Provider=Microsoft.Jet.OLEDB.4.0;Data Source=’ + Server.MapPath(‘nwind.mdb’) + ‘;’; string strsql = ‘Select * from Customers’; OleDbConnection cn = new OleDbConnection(strConn); DataSet ds = new DataSet(); OleDbDataAdapter da = new OleDbDataAdapter(strsql, cn); da.Fill(ds, ‘T1’); DataGrid1.DataSource = ds; DataGrid1.DataBind();