Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2014
33
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.26 KB | None | 0 0
  1. protected void cblList1_SelectedIndexChanged(object sender, EventArgs e)
  2. {
  3. foreach (ListItem list1 in cblList1.Items)
  4. {
  5. if (list1 .Selected == true)
  6. {
  7. LoadCheckBoxListList2(list1);
  8. }
  9. }
  10. }
  11.  
  12. private void LoadCheckBoxListList2(ListItem itemList1)
  13. {
  14. SqlCommand cmd = new SqlCommand("SELECT DISTINCT tbl_information.route AS ROUTE FROM tbl_information INNER JOIN tbl_regional ON tbl_information.region = tbl_regional.id_regional WHERE tbl_information.supervisor = " + "'" + itemList1 + "'", conn);
  15. SqlDataAdapter da = new SqlDataAdapter(cmd);
  16. DataSet ds = new DataSet();
  17. da.Fill(ds);
  18.  
  19. cblRutas.DataSource = ds;
  20. cblRutas.DataValueField = "ROUTE";
  21. cblRutas.DataBind();
  22. }
  23.  
  24. for (int i = 0; i < checkedListBox1.Items.Count; i++)
  25. {
  26. if (checkedListBox1.GetItemChecked(i))
  27. {
  28. string str = (string)checkedListBox1.Items[i];
  29. //Do your function call here
  30. }
  31. }
  32.  
  33. protected void cblList1_SelectedIndexChanged(object sender, EventArgs e)
  34. {
  35. List<string> ids = new List<string>();
  36. foreach (ListItem list1 in cblList1.Items)
  37. {
  38. if (list1 .Selected == true)
  39. {
  40. ids.Add(list1.ToString());
  41. }
  42. }
  43.  
  44. LoadCheckBoxListList2(ids);
  45. }
  46.  
  47. private void LoadCheckBoxListList2(List<string> ids)
  48. {
  49. string idsString = string.Join(", ", ids);// WARNING: carefull, SQL-injection is possible here, better to filter the input
  50. SqlCommand cmd = new SqlCommand("SELECT DISTINCT tbl_information.route AS ROUTE FROM tbl_information INNER JOIN tbl_regional ON tbl_information.region = tbl_regional.id_regional WHERE tbl_information.supervisor IN (" + idsString + ")", conn);
  51.  
  52. SqlDataAdapter da = new SqlDataAdapter(cmd);
  53. DataSet ds = new DataSet();
  54. da.Fill(ds);
  55.  
  56. cblRutas.DataSource = ds;
  57. cblRutas.DataValueField = "ROUTE";
  58. cblRutas.DataBind();
  59. }
  60.  
  61. protected void cblList1_SelectedIndexChanged(object sender, EventArgs e)
  62. {
  63. List<string> list1 = new List<string>();
  64. foreach (ListItem itemList1 in cblList1.Items)
  65. {
  66. if (itemList1 .Selected == true)
  67. {
  68. list1.Add(itemList1.Text)
  69. }
  70. }
  71. LoadCheckBoxListList2(list1);
  72. }
  73.  
  74. private void LoadCheckBoxListList2(List<string> list1)
  75. {
  76. DataTable dt = new DataTable("R");
  77. dt.Columns.Add("Route", typeof(string));
  78.  
  79. foreach (string li in list1)
  80. {
  81. string query = @"SELECT DISTINCT tbl_information.route AS ROUTE FROM tbl_information INNER JOIN tbl_regional ON tbl_information.region = tbl_regional.id_regional WHERE tbl_information.supervisor = '" + li + "'";
  82.  
  83. SqlCommand cmd = new SqlCommand(query, conn);
  84. SqlDataAdapter da = new SqlDataAdapter(cmd);
  85. DataSet ds = new DataSet();
  86. da.Fill(ds);
  87.  
  88. bool b = false;
  89.  
  90. foreach (DataRow item in ds.Tables[0].Rows)
  91. {
  92. if (!b)
  93. {
  94. dt.Rows.Add(item[0] + " (" + li + ")");
  95. b = true;
  96. continue;
  97. }
  98.  
  99. dt.Rows.Add(item.ItemArray);
  100. }
  101. }
  102.  
  103. cblRutas.DataSource = dt;
  104. cblRutas.DataValueField = "ROUTE";
  105. cblRutas.DataBind();
  106. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement