Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- try
- {
- con.Open();
- SqlDataReader myReader = null;
- SqlCommand myCom = new SqlCommand("select ID,client from tposClient where CardNo='" + cNo + "'", con);
- myReader = myCom.ExecuteReader();
- Panel panel1 = new Panel();
- panel1.Style["text-align"] = "Center";
- panel1.Style["background"] = "blue";
- div_login.Visible = false;
- while (myReader.Read())
- {
- string b = myReader["client"].ToString();
- string id = myReader["ID"].ToString();
- Button btn = new Button();
- btn.Text = b;
- btn.ID = id;
- btn.Style["width"] = "100px";
- btn.Click += new EventHandler(btn_Click);
- panel1.Controls.Add(btn);
- panel1.Controls.Add(new LiteralControl("<br />"));
- form1.Style.Add("display", "block");
- form1.Controls.Add(panel1);
- }
- }
- catch (Exception k)
- {
- Console.WriteLine(k.ToString());
- }
- finally
- {
- cmdselect.Dispose();
- if (con != null)
- {
- con.Close();
- }
- }
- <asp:ListView ID="lv1" runat="server" OnItemDataBound="lv1_ItemDataBound">
- <ItemTemplate>
- <asp:Button ID="btn1" runat="server" Text="my Text />
- </ItemTemplate>
- </asp:ListView>
- //Your data access code
- Dictionary<string, string> buttonIdsWithText = new Dictionary<string, string>();
- while(myReader.Read())
- {
- string buttonText = myReader["client"].ToString();
- string buttonId = myReader["ID"].ToString();
- buttonIdsWithText.Add(buttonId, buttonText);
- }
- lv1.DataSource = buttonIdsWithText;
- lv1.DataBind();
- public void lv1_ItemDataBound(object sender, ListViewItemEventArgs e)
- {
- if (e.Item.ItemType != ListViewItemType.DataItem)
- {
- return;
- }
- KeyValuePair<string, string> idWithText =
- (KeyValuePair<string, string>)e.Item.DataItem;
- Button myButton = e.Item.FindControl("btn1") as Button;
- myButton.Text = idWithText.Value;
- }
Add Comment
Please, Sign In to add comment