Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2020
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.44 KB | None | 0 0
  1. Class1 objektum = new Class1();
  2. protected void Page_Load(object sender, EventArgs e)
  3. {
  4. if (!IsPostBack)
  5. {
  6. fillDropdown();
  7.  
  8. fillDropdown2();
  9. }
  10. }
  11. private void fillOsztaly()
  12. {
  13. string jarat = DropDownList1.SelectedItem.Value;
  14. string file = "~/jarat/" + jarat + ".txt";
  15. int i = 1;
  16. using (StreamReader sr = new StreamReader(Server.MapPath(file)))
  17. {
  18. string line;
  19. while ((line = sr.ReadLine()) != null)
  20. {
  21. if (line.Contains("IRÁNY:"))
  22. {
  23. if (String.IsNullOrEmpty(objektum.Honnan))
  24. objektum.Honnan = line.Substring(7).Trim();
  25. else
  26. objektum.Hova = line.Substring(7).Trim();
  27. i = 1;
  28. }
  29. else
  30. {
  31. if (String.IsNullOrEmpty(objektum.Hova))
  32. objektum.Indulas.Add(i++ + ". " +line.Trim());
  33. else
  34. objektum.Erkezes.Add(i++ + ". " +line.Trim());
  35. }
  36. }
  37.  
  38. }
  39. }
  40.  
  41. protected void fillDropdown() {
  42. string[] fill = Directory.GetFiles(Server.MapPath("~/jarat/"),"*.txt");
  43. for (int x = 0; x < fill.Length; x++) {
  44. fill[x] = Path.GetFileNameWithoutExtension(fill[x]);
  45. }
  46.  
  47. DropDownList1.DataSource = fill;
  48. DropDownList1.DataBind();
  49. }
  50. protected void fillDropdown2() {
  51. DropDownList2.Items.Clear();
  52. fillOsztaly();
  53. DropDownList2.Items.Add(objektum.Honnan);
  54. DropDownList2.Items.Add(objektum.Hova);
  55. }
  56. protected void Button1_Click(object sender, EventArgs e)
  57. {
  58. fillOsztaly();
  59. if (DropDownList2.SelectedIndex == 0)
  60. {
  61. GridView1.DataSource = objektum.Indulas;
  62. }
  63. else GridView1.DataSource = objektum.Erkezes;
  64.  
  65. GridView1.DataBind();
  66. }
  67.  
  68. protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
  69. {
  70. fillDropdown2();
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement