Guest User

Untitled

a guest
May 22nd, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.84 KB | None | 0 0
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.Data;
  5. using System.Data.SqlClient;
  6. using System.Diagnostics;
  7. using System.Web;
  8. using System.Web.UI;
  9. using System.Web.UI.WebControls;
  10. using ADONET_namespace;
  11.  
  12. namespace AddFileToSQL
  13. {
  14. public partial class DataMatch : _Default
  15. {
  16. protected System.Web.UI.WebControls.PlaceHolder phTextBoxes;
  17. protected System.Web.UI.WebControls.PlaceHolder phDropDownLists;
  18. protected System.Web.UI.WebControls.Button btnAnotherRequest;
  19. protected System.Web.UI.WebControls.Panel pnlCreateData;
  20. protected System.Web.UI.WebControls.Literal lTextData;
  21. protected System.Web.UI.WebControls.Panel pnlDisplayData;
  22. //Panel pnlDropDownList;
  23.  
  24. protected static string inputfile2;
  25. static string[] headers = null;
  26. static string[] data = null;
  27. static string[] data2 = null;
  28. static DataTable myInputFile = new DataTable("MyInputFile");
  29. static string[] myUserSelections;
  30.  
  31. // a Property that manages a counter stored in ViewState
  32. protected int NumberOfControls
  33. {
  34. get { return (int)ViewState["NumControls"]; }
  35. set { ViewState["NumControls"] = value; }
  36. }
  37.  
  38. public void EditRecord(object recordID)
  39. {
  40. SelectedRecordID = recordID;
  41. // Load record from database and show in control
  42. }
  43.  
  44. protected object SelectedRecordID
  45. {
  46. get
  47. {
  48. return ViewState["SelectedRecordID"];
  49. }
  50. set
  51. {
  52. ViewState["SelectedRecordID"] = value;
  53. }
  54. }
  55.  
  56. // Page Load
  57. private void Page_Load(object sender, System.EventArgs e)
  58. {
  59. if (!Page.IsPostBack)
  60. {
  61. this.NumberOfControls = 0;
  62. }
  63. }
  64.  
  65. // Add DropDownList Control to Placeholder
  66. private void CreateDropDownLists()
  67. {
  68. for (int counter = 0; counter < NumberOfControls; counter++)
  69. {
  70. DropDownList ddl = new DropDownList();
  71. SqlDataReader dr = ADONET_methods.DisplayTableColumns(targettable);
  72. ddl.ID = "DropDownListID" + (counter + 1).ToString();
  73. ddl.DataTextField = "COLUMN_NAME";
  74. ddl.DataValueField = "COLUMN_NAME";
  75. ddl.DataSource = dr;
  76. ddl.DataBind();
  77.  
  78. //myUserSelections[counter] = "";
  79.  
  80. ddl.AutoPostBack = true;
  81. ddl.EnableViewState = true; //Preserves View State info on Postbacks
  82. ddl.Style["position"] = "absolute";
  83. ddl.Style["top"] = 100 * counter + 80 + "px";
  84. ddl.Style["left"] = 250 + "px";
  85. ddl.SelectedIndexChanged += new EventHandler(SelectedIndexChanged);
  86.  
  87. pnlDisplayData.Controls.Add(ddl);
  88. pnlDisplayData.Controls.Add(new LiteralControl("<br><br><br>"));
  89. pnlDisplayData.Visible = true;
  90.  
  91. // pnlDropDownList.FindControl(ddl.ID);
  92. dr.Close();
  93. }
  94. }
  95.  
  96. protected void SelectedIndexChanged(object sender, EventArgs e)
  97. {
  98. DropDownList ddl = (DropDownList)sender;
  99. string ID = ddl.ID;
  100. }
  101.  
  102. // Add TextBoxes Control to Placeholder
  103. private void RecreateDropDownLists()
  104. {
  105. for (int counter = 0; counter < NumberOfControls; counter++)
  106. {
  107. DropDownList ddl = new DropDownList();
  108. SqlDataReader dr = ADONET_methods.DisplayTableColumns(targettable);
  109.  
  110. ddl.ID = "DropDownListID" + (counter + 1).ToString();
  111. ddl.DataTextField = "COLUMN_NAME";
  112. ddl.DataValueField = "COLUMN_NAME";
  113. ddl.DataSource = dr;
  114. ddl.DataBind();
  115. myUserSelections[counter] = "";
  116. dr.Close();
  117.  
  118. ddl.AutoPostBack = true;
  119. ddl.EnableViewState = false; //Preserves View State info on Postbacks
  120. ddl.Style["position"] = "absolute";
  121. ddl.Style["top"] = 100 * counter + 80 + "px";
  122. ddl.Style["left"] = 250 + "px";
  123. pnlDisplayData.Controls.Add(ddl);
  124. pnlDisplayData.Controls.Add(new LiteralControl("<br><br><br>"));
  125. }
  126. }
  127.  
  128. // Create TextBoxes and DropDownList data here on postback.
  129. protected override void CreateChildControls()
  130. {
  131. // create the child controls if the server control does not contains child controls
  132. this.EnsureChildControls();
  133.  
  134. // Creates a new ControlCollection.
  135. this.CreateControlCollection();
  136.  
  137. // Here we are recreating controls to persist the ViewState on every post back
  138. if (Page.IsPostBack)
  139. {
  140. RecreateDropDownLists();
  141. RecreateLabels();
  142. }
  143. // Create these conrols when asp.net page is created
  144. else
  145. {
  146. PopulateFileInputTable();
  147. CreateDropDownLists();
  148. CreateLabels();
  149. }
  150.  
  151. // Prevent child controls from being created again.
  152. this.ChildControlsCreated = true;
  153. }
  154.  
  155. // Read all the data from TextBoxes and DropDownLists
  156. protected void btnSubmit_Click(object sender, System.EventArgs e)
  157. {
  158. int cnt = FindOccurence("DropDownListID");
  159. EditRecord("DropDownListID" + Convert.ToString(cnt + 1));
  160. AppendRecords();
  161. pnlDisplayData.Visible = false;
  162. }
  163.  
  164. private int FindOccurence(string substr)
  165. {
  166. string reqstr = Request.Form.ToString();
  167. return ((reqstr.Length - reqstr.Replace(substr, "").Length) / substr.Length);
  168. }
  169. }
  170. }
Add Comment
Please, Sign In to add comment