Skip to content
Loading
display all data from gridview column
  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Data;  
  4. using System.Linq;  
  5. using System.Web;  
  6. using System.Web.UI;  
  7. using System.Web.UI.WebControls;  
  8. namespace GridViewWithoutDBandStateMngmt  
  9. {  
  10. public partial class WebForm1 : System.Web.UI.Page  
  11. {  
  12. protected void Page_Load(object sender, EventArgs e)  
  13. {  
  14. }  
  15. protected void btnSave_Click(object sender, EventArgs e)  
  16. {  
  17. if (txtStID.Text != string.Empty)  
  18. {  
  19. DataTable dt = new DataTable();  
  20. dt.Columns.Add("Student ID");  
  21. for (int row = 0; row < GridView1.Rows.Count; row++)  
  22. {  
  23. DataRow dr = dt.NewRow();  
  24. dr[0] = GridView1.Rows[row].Cells[0].Text;  
  25. dt.Rows.Add(dr);  
  26. }  
  27. dt.Rows.Add(txtStID.Text);  
  28. GridView1.DataSource = dt;  
  29. GridView1.DataBind();  
  30. txtStID.Text = string.Empty;  
  31. loop();  
  32. }  
  33. }  
  34. protected void OnRowDataBound(object sender, GridViewRowEventArgs e)  
  35. {  
  36. if (e.Row.RowType == DataControlRowType.DataRow)  
  37. {  
  38. foreach (GridViewRow row in GridView1.Rows)  
  39. {  
  40. string name = e.Row.Cells[0].Text;  
  41. ScriptManager.RegisterClientScriptBlock(this.Page, this.Page.GetType(), "alert""alert('" + name + "');"true);  
  42. }  
  43. }  
  44. }  
  45. }  
  46. }  
but is displaying only current inserted row i want to display all data from the row

5 Replies

Know the answer? Post it — somebody with the same question will find it here.