Guest User

Untitled

a guest
Jan 21st, 2019
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.12 KB | None | 0 0
  1. try
  2. {
  3. con.Open();
  4. SqlDataReader myReader = null;
  5. SqlCommand myCom = new SqlCommand("select ID,client from tposClient where CardNo='" + cNo + "'", con);
  6.  
  7. myReader = myCom.ExecuteReader();
  8.  
  9. Panel panel1 = new Panel();
  10. panel1.Style["text-align"] = "Center";
  11. panel1.Style["background"] = "blue";
  12. div_login.Visible = false;
  13.  
  14. while (myReader.Read())
  15. {
  16. string b = myReader["client"].ToString();
  17. string id = myReader["ID"].ToString();
  18.  
  19. Button btn = new Button();
  20. btn.Text = b;
  21. btn.ID = id;
  22. btn.Style["width"] = "100px";
  23. btn.Click += new EventHandler(btn_Click);
  24. panel1.Controls.Add(btn);
  25.  
  26. panel1.Controls.Add(new LiteralControl("<br />"));
  27. form1.Style.Add("display", "block");
  28. form1.Controls.Add(panel1);
  29. }
  30. }
  31. catch (Exception k)
  32. {
  33. Console.WriteLine(k.ToString());
  34. }
  35. finally
  36. {
  37. cmdselect.Dispose();
  38. if (con != null)
  39. {
  40. con.Close();
  41. }
  42. }
  43.  
  44. <asp:ListView ID="lv1" runat="server" OnItemDataBound="lv1_ItemDataBound">
  45. <ItemTemplate>
  46. <asp:Button ID="btn1" runat="server" Text="my Text />
  47. </ItemTemplate>
  48. </asp:ListView>
  49.  
  50. //Your data access code
  51. Dictionary<string, string> buttonIdsWithText = new Dictionary<string, string>();
  52. while(myReader.Read())
  53. {
  54. string buttonText = myReader["client"].ToString();
  55. string buttonId = myReader["ID"].ToString();
  56. buttonIdsWithText.Add(buttonId, buttonText);
  57. }
  58. lv1.DataSource = buttonIdsWithText;
  59. lv1.DataBind();
  60.  
  61. public void lv1_ItemDataBound(object sender, ListViewItemEventArgs e)
  62. {
  63. if (e.Item.ItemType != ListViewItemType.DataItem)
  64. {
  65. return;
  66. }
  67.  
  68. KeyValuePair<string, string> idWithText =
  69. (KeyValuePair<string, string>)e.Item.DataItem;
  70. Button myButton = e.Item.FindControl("btn1") as Button;
  71. myButton.Text = idWithText.Value;
  72. }
Add Comment
Please, Sign In to add comment