Wednesday, 7 November 2012

ASP.NET - C# - How to loop through the gridview using JavaScript


To illustrate how to loop through the gridview using javascript 1. Create empty web application project 2. Add Web form to it. 3. Add GridView to the form. 4. Add ADO.NET Entity DataModel - connect to the database (watch video to see all the details). 5. Add the following code to pageLoad function - it will populate grid view with data from my table. ( have very simple table called Dpt with 2 columns in it: - DepartmentId - DepartmentName both columns will be displayed in the grid protected void Page_Load(object sender, EventArgs e) { using (var db = new WebApplication6.SchoolEntities1()) { this.GridView1.DataSource = db.Dpts.ToList(); this.GridView1.DataBind(); } } 6. Now if you run your program - grid view will display data from DPT table. 7. Add new button to the page 8. Add custom validator to the page. Ensure it has ClientValidationFunction specified. 9. Add the following javascript code. if there is Department named "No Name" - page will display error message.

No comments:

Post a Comment