adding the values to the grid dynamically and with unique id

Please support our ASP.NET advertiser: Intel Parallel Studio Home
Reply

Join Date: Oct 2008
Posts: 23
Reputation: kapil.tandon is an unknown quantity at this point 
Solved Threads: 0
kapil.tandon kapil.tandon is offline Offline
Newbie Poster

adding the values to the grid dynamically and with unique id

 
0
  #1
Nov 6th, 2008
  1. private void AddRecordToGrid()
  2. {
  3. try
  4. {
  5.  
  6. datatable dt = new datable();
  7. if (Session["SampleDataTable"] == null)
  8. {
  9. dt.Columns.Add(new DataColumn("ID", typeof(string)));
  10. dt.Columns.Add(new DataColumn("Qtr", typeof(string)));
  11.  
  12. dt.Columns.Add(new DataColumn("Exp", typeof(string)));
  13. dt.Columns.Add(new DataColumn("Partner", typeof(string)));
  14. dt.Columns.Add(new DataColumn("Net", typeof(string)));
  15. dr = dt.NewRow();
  16. }
  17. else
  18. {
  19. dt= (DataTable)Session["SampleDataTable"];
  20. }
  21.  
  22. dr = dt.NewRow();
  23.  
  24.  
  25. if (dr.IsNull(0))
  26. {
  27. //dr = dt.NewRow();
  28. dr[0] = txtD.Text;
  29. dr[1] = cbQuarter.SelectedItem.Text;
  30.  
  31. dr[2] =Exp.Text;
  32. dr[3] = txtPartner.Text;
  33. dr[4] = lblNet.Text;
  34. dt.Rows.Add(dr);
  35. DataView dv = new DataView(dt);
  36. grdBudget.DataSource = dv;
  37. grdBudget.DataBind();
  38. }
  39. for (int i = 0; i < grdBudget.Rows.Count; i++)
  40. {
  41.  
  42. if (!dr.IsNull(0))
  43. {
  44. if (txtBudgetID.Text != dr[0].ToString())
  45. {
  46. dr = dt.NewRow();
  47. dr[0] = txtD.Text;
  48. dr[1] = cboQuarter.SelectedItem.Text;
  49.  
  50. dr[2] = Exp.Text;
  51. dr[3] = txtPartner.Text;
  52. dr[4] = lblNet.Text;
  53. dt.Rows.Add(dr);
  54. DataView dv = new DataView(dt);
  55. grdBudget.DataSource = dv;
  56. grdBudget.DataBind();
  57. }
  58. }
  59. }
  60. Session["SampleDataTable"] = dt;
  61.  
  62. }
  63.  
  64.  
  65. catch (Exception ex)
  66. {
  67. }

the problem i m facing wid this code id that the new data row is added every time when this function is called and it enters ito the loop of the if(dr.isnull(0)) . i want only the values with unique id shud be entered. if the value wid the existin id id entere, it shud not be allowed to enter.
Last edited by cscgal; Nov 6th, 2008 at 12:18 pm. Reason: Added code tags
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC