OracleConnection cn = new OracleConnection("user id=scott;password=tiger;data source=ganesh1"); OracleDataAdapter da = new OracleDataAdapter("select * from emp", cn); ds = new DataSet(); da.Fill(ds, "temp"); GridView1.DataSource = ds.Tables[0]; GridView1.DataBind();
protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e) { //checking whether rowtype is datacontrolrowtype if (e.Row.RowType == DataControlRowType.DataRow) { double annsal;//getting the required data from database annsal =double .Parse ( ds.Tables[0].Rows[e.Row.RowIndex]["sal"].ToString()) * 12;//initializing and adding label control to gridview Label l1=new Label(); l1.Text =annsal .ToString (); e.Row .Cells [1].Controls .Add (l1); //checking tha annsal and drawing the row with particular color if (annsal > 1000) { e.Row.BackColor = System.Drawing.Color.Red; } else e.Row.BackColor = System.Drawing.Color.Gray; } }