943,769 Members | Top Members by Rank

Ad:
  • ASP.NET Discussion Thread
  • Unsolved
  • Views: 560
  • ASP.NET RSS
Aug 23rd, 2009
0

databound controls

Expand Post »
Hi ,

I need to create a page that has databound controls . eg.

Say i have a row with the following columns
1. TrackKey VARCHAR(50)
2. State VARCHAR(50)
3. Reason VARCHAR(50)
4. DateChanged DATETIME

------------------------------------------------------------

Now for each row in the table, the controls should be like this
1. TrackKey - Label
2. State - dropdownlist
3. Reason textbox
4. DateChanged - 3 dropdownlists [years, months , days]

---------------------------------------------------------------

I am able to dynamically load these controls, but due to postback i cannot save the information that changed.

can anyone give me some advice on how to change this ?

here is my code for loading:

ASP.NET Syntax (Toggle Plain Text)
  1. void GenerateList()
  2. {
  3. // This method will generate a table for editing states
  4.  
  5. // Dataset for storing values
  6. DataSet setGetTrackings = new DataSet();
  7.  
  8. // In the grid - the controls
  9. Label TrackKey = new Label();
  10. DropDownList SetState = new DropDownList();
  11. TextBox reason = new TextBox();
  12. DropDownList Days = new DropDownList();
  13. DropDownList Months = new DropDownList();
  14. DropDownList Years = new DropDownList();
  15. HtmlTableCell htmlCell = null;
  16. HtmlTableRow htmlRow = null;
  17.  
  18. HandleStates entry = new HandleStates();
  19.  
  20. // finally we will count the rows for inserting
  21. int rowcount = 2;
  22.  
  23. int IndexCount = 0;
  24.  
  25. //Set the tables.
  26. if (setGetTrackings != null && setGetTrackings.Tables.Count > 0)
  27. {
  28. foreach (DataRow row in setGetTrackings.Tables[0].Rows)
  29. {
  30. // Create the controls.
  31. TrackKey = new Label();
  32. SetState = new DropDownList();
  33. htmlCell = null;
  34. htmlRow = null;
  35. reason = new TextBox();
  36. Days = new DropDownList();
  37. Months = new DropDownList();
  38. Years = new DropDownList();
  39.  
  40. #region Populate Controls
  41. // Set the values
  42. TrackKey.Text = row[0].ToString();
  43. SetState.Items.Add(row[7].ToString());
  44. reason.TextMode = TextBoxMode.MultiLine;
  45.  
  46. // Add more Items To The DropDown
  47. SetState.Items.Add("--New State--");
  48. SetState.Items.Add("Visiting x Branch");
  49. SetState.Items.Add("Visiting y Branch");
  50. SetState.Items.Add("Received");
  51. SetState.Items.Add("Ready To Go");
  52. SetState.Items.Add("Not Ready To Go");
  53. SetState.Items.Add("Submitted");
  54. SetState.Items.Add("Acquired");
  55. SetState.Items.Add("Denied");
  56.  
  57. // Adding attributes to the dropdown
  58.  
  59. int IDDay = 10000000 + rowcount;
  60. int IDMonth = 11000000 + rowcount;
  61. int IDYear = 12000000 + rowcount;
  62. int IDTetbox = 13000000 + rowcount;
  63.  
  64. SetState.ID = rowcount.ToString();
  65. reason.ID = IDTetbox.ToString();
  66. Days.ID = IDDay.ToString();
  67. Months.ID = IDMonth.ToString();
  68. Years.ID = IDYear.ToString();
  69.  
  70. int D1 = 1;
  71. int D2 = 32;
  72.  
  73. while (D1 < D2)
  74. {
  75. Days.Items.Add(D1.ToString());
  76. D1++;
  77. }
  78.  
  79. int M1 = 1;
  80. int M2 = 13;
  81.  
  82. while (M1 < M2)
  83. {
  84. Months.Items.Add(M1.ToString());
  85. M1++;
  86. }
  87.  
  88. string CurrentYear = string.Format("{0:yyyy}", DateTime.Now);
  89.  
  90. int Y1 = int.Parse(CurrentYear);
  91. int Y2 = int.Parse(CurrentYear) + 3;
  92.  
  93. while (Y1 < Y2)
  94. {
  95. Years.Items.Add(Y1.ToString());
  96. Y1++;
  97. }
  98.  
  99. #endregion
  100.  
  101. // Create the row
  102. htmlRow = new HtmlTableRow();
  103.  
  104. // Populate the cells
  105.  
  106. #region Populate the main cells
  107. // Create the track key cell.
  108. htmlCell = new HtmlTableCell();
  109. htmlCell.Attributes.Add("class", "UserManageField");
  110. htmlCell.Controls.Add(TrackKey);
  111. htmlRow.Cells.Add(htmlCell);
  112.  
  113. // Create the SetState cell.
  114. htmlCell = new HtmlTableCell();
  115. //htmlCell.Attributes.Add("class", "FormtextBox");
  116. htmlCell.Controls.Add(SetState);
  117. htmlRow.Cells.Add(htmlCell);
  118. #endregion
  119.  
  120. tblTrackings.Rows.Add(htmlRow);
  121.  
  122. rowcount++;
  123.  
  124. // New Row To insert hidden fields
  125. htmlRow = new HtmlTableRow();
  126.  
  127. #region Blank cells
  128. // adding seven blank columns
  129. htmlCell = new HtmlTableCell();
  130. htmlCell.InnerText = " ";
  131. htmlRow.Cells.Add(htmlCell);
  132.  
  133. htmlCell = new HtmlTableCell();
  134. htmlCell.InnerText = " ";
  135. htmlRow.Cells.Add(htmlCell);
  136.  
  137. htmlCell = new HtmlTableCell();
  138. htmlCell.InnerText = " ";
  139. htmlRow.Cells.Add(htmlCell);
  140.  
  141. htmlCell = new HtmlTableCell();
  142. htmlCell.InnerText = " ";
  143. htmlRow.Cells.Add(htmlCell);
  144.  
  145. htmlCell = new HtmlTableCell();
  146. htmlCell.InnerText = " ";
  147. htmlRow.Cells.Add(htmlCell);
  148.  
  149. htmlCell = new HtmlTableCell();
  150. htmlCell.InnerText = " ";
  151. htmlRow.Cells.Add(htmlCell);
  152.  
  153. htmlCell = new HtmlTableCell();
  154. htmlCell.InnerText = " ";
  155. htmlRow.Cells.Add(htmlCell);
  156. #endregion
  157.  
  158.  
  159. // Add some attributes
  160. reason.Style.Add("visibility", "hidden");
  161. Days.Style.Add("visibility", "hidden");
  162. Months.Style.Add("visibility", "hidden");
  163. Years.Style.Add("visibility", "hidden");
  164.  
  165. // Create the date cell.
  166. htmlCell = new HtmlTableCell();
  167. reason.Text = "This is a hidden textbox";
  168. htmlCell.Controls.Add(reason);
  169. htmlCell.Controls.Add(Days);
  170. Days.Text = "1";
  171. htmlCell.Controls.Add(Months);
  172. Months.Text = "1";
  173. htmlCell.Controls.Add(Years);
  174. Years.Text = "2009";
  175. htmlRow.Cells.Add(htmlCell);
  176.  
  177. tblTrackings.Rows.Add(htmlRow);
  178.  
  179. rowcount++;
  180.  
  181. // New Row To insert hidden fields
  182. htmlRow = new HtmlTableRow();
  183.  
  184. #region Blank cells
  185. // adding seven blank columns
  186. htmlCell = new HtmlTableCell();
  187. htmlCell.InnerText = " ";
  188. htmlRow.Cells.Add(htmlCell);
  189.  
  190. htmlCell = new HtmlTableCell();
  191. htmlCell.InnerText = " ";
  192. htmlRow.Cells.Add(htmlCell);
  193.  
  194. htmlCell = new HtmlTableCell();
  195. htmlCell.InnerText = " ";
  196. htmlRow.Cells.Add(htmlCell);
  197.  
  198. htmlCell = new HtmlTableCell();
  199. htmlCell.InnerText = " ";
  200. htmlRow.Cells.Add(htmlCell);
  201.  
  202. htmlCell = new HtmlTableCell();
  203. htmlCell.InnerText = " ";
  204. htmlRow.Cells.Add(htmlCell);
  205.  
  206. htmlCell = new HtmlTableCell();
  207. htmlCell.InnerText = " ";
  208. htmlRow.Cells.Add(htmlCell);
  209.  
  210. htmlCell = new HtmlTableCell();
  211. htmlCell.InnerText = " ";
  212. htmlRow.Cells.Add(htmlCell);
  213. #endregion
  214.  
  215. // Create the date cell.
  216. htmlCell = new HtmlTableCell();
  217. htmlCell.Controls.Add(Days);
  218. Days.Text = "1";
  219. htmlCell.Controls.Add(Months);
  220. Months.Text = "1";
  221. htmlCell.Controls.Add(Years);
  222. Years.Text = "2009";
  223. htmlRow.Cells.Add(htmlCell);
  224.  
  225. tblTrackings.Rows.Add(htmlRow);
  226.  
  227. rowcount++;
  228.  
  229. #region Script
  230. SetState.SelectedIndex = 0;
  231. Days.SelectedIndex = 0;
  232. Months.SelectedIndex = 0;
  233. Years.SelectedIndex = 0;
  234.  
  235. SetState.Attributes.Add("onChange", "SetVisibility();");
  236.  
  237. StringBuilder scriptBuilder = new StringBuilder();
  238.  
  239. scriptBuilder.Append("<script type='text/javascript' language='javascript'>");
  240.  
  241. scriptBuilder.Append("function SetVisibility()");
  242. scriptBuilder.Append("{");
  243.  
  244. scriptBuilder.AppendFormat("var ddSetstate = document.getElementById('{0}'); ", SetState.ClientID);
  245. scriptBuilder.Append("var ddSetstate_selectedelement = ddSetstate.options[ddSetstate.selectedIndex].text; ");
  246. scriptBuilder.AppendFormat("var ReasonTextBox = document.getElementById('{0}'); ", reason.ClientID);
  247. scriptBuilder.AppendFormat("var dayCBO = document.getElementById('{0}'); ", Days.ClientID);
  248. scriptBuilder.AppendFormat("var monthCBO = document.getElementById('{0}'); ", Months.ClientID);
  249. scriptBuilder.AppendFormat("var yearCBO = document.getElementById('{0}'); ", Years.ClientID);
  250.  
  251. scriptBuilder.Append("if (ddSetstate_selectedelement == 'Not Ready To Go') ");
  252. scriptBuilder.Append(" { ");
  253. scriptBuilder.Append(" ReasonTextBox.style.visibility = ''; ");
  254. scriptBuilder.Append(" dayCBO.style.visibility = 'hidden'; ");
  255. scriptBuilder.Append(" monthCBO.style.visibility = 'hidden'; ");
  256. scriptBuilder.Append(" yearCBO.style.visibility = 'hidden'; ");
  257. scriptBuilder.Append(" } ");
  258.  
  259. scriptBuilder.Append("else if (ddSetstate_selectedelement == 'Successfully Submitted') ");
  260. scriptBuilder.Append(" { ");
  261. scriptBuilder.Append(" dayCBO.style.visibility = ''; ");
  262. scriptBuilder.Append(" monthCBO.style.visibility = ''; ");
  263. scriptBuilder.Append(" yearCBO.style.visibility = ''; ");
  264. scriptBuilder.Append(" ReasonTextBox.style.visibility = 'hidden'; ");
  265. scriptBuilder.Append(" } ");
  266.  
  267. scriptBuilder.Append(" else ");
  268. scriptBuilder.Append(" { ");
  269. scriptBuilder.Append(" dayCBO.style.visibility = 'hidden'; ");
  270. scriptBuilder.Append(" monthCBO.style.visibility = 'hidden'; ");
  271. scriptBuilder.Append(" yearCBO.style.visibility = 'hidden'; ");
  272. scriptBuilder.Append(" ReasonTextBox.style.visibility = 'hidden'; ");
  273. scriptBuilder.Append(" } ");
  274.  
  275. scriptBuilder.Append("JSetStates();");
  276.  
  277. scriptBuilder.Append(" } ");
  278.  
  279. scriptBuilder.Append("</script>");
  280.  
  281. base.ClientScript.RegisterClientScriptBlock(typeof(void), "Myscripts", scriptBuilder.ToString());
  282. #endregion
  283. }
  284. }

PLEASE HELP !!!!!!!
Similar Threads
cVz
Reputation Points: 29
Solved Threads: 7
Junior Poster
cVz is offline Offline
139 posts
since Mar 2008
Aug 23rd, 2009
0

Re: databound controls

Are you creating the controls on the postback? If you don't then you won't see the updated data.
Featured Poster
Reputation Points: 1749
Solved Threads: 735
Senior Poster
sknake is offline Offline
3,948 posts
since Feb 2009
Aug 24th, 2009
0

Re: databound controls

my friend u are creating controls on the fly..

i think you should save the data cumming frm database to an object..

and updating the data update the object...and load them again..

i think using session u can figure out the situation..
Reputation Points: 28
Solved Threads: 106
Banned
dnanetwork is offline Offline
633 posts
since May 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in ASP.NET Forum Timeline: Populating a TreeView
Next Thread in ASP.NET Forum Timeline: Urgent help requried with connection string





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC