.NET/ASP.NET interview Questions - Demonstrate Render and PreRender?
Shivprasad Koirala
protected override void OnPreRender(EventArgs e){ foreach (GridViewRow row in GridView1.Rows) { row.ForeColor = Color.Blue; } }
protected override void Render(HtmlTextWriter writer){ writer.Write("This displays the grid in blue color"); base.Render(writer);}
using System.Drawing;using System.Collections;namespace Data{ public class Customer { public string CustomerCode { set; get; } public string CustomerName { set; get; } } public partial class WebForm1 : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { LoadGrid(); } public void LoadGrid() { ArrayList objArray = new ArrayList(); Customer ObjCustomer = new Customer(); ObjCustomer.CustomerCode = "1001"; ObjCustomer.CustomerName = "shiv"; objArray.Add(ObjCustomer); ObjCustomer = new Customer(); ObjCustomer.CustomerCode = "1002"; ObjCustomer.CustomerName = "Feroz"; objArray.Add(ObjCustomer); GridView1.DataSource = objArray; GridView1.DataBind(); } protected override void OnPreRender(EventArgs e) { foreach (GridViewRow row in GridView1.Rows) { row.ForeColor = Color.Blue; } } protected override void Render(HtmlTextWriter writer) { writer.Write("This displays the grid in blue color"); base.Render(writer); } }}
Please click here to see more .NET/ASP.NET interview questions