Hi,
after spending lot of time on google i am fadeup
i have a dynamic tab control in which i am able to make dynamic buttons and i am also able to get whole row of a table product in button's tag but i do not know how to retrive values from it i am not fimilar with tags
basicaly i have 8 fields in Tbl_Products now want to send name, price and quantity(no. of times button clicked)of the product to a list box on button cilck event here's my code
private void AddProductsToTab()
{
int i = 1;
foreach (TabPage tp in tabControl1.TabPages)
{
FlowLayoutPanel flp = new FlowLayoutPanel();
flp.Dock = DockStyle.Fill;
SqlDataReader reader = null;
SqlConnection con = new SqlConnection(ConStr);
try
{
string query = "SELECT * FROM Tbl_Products WHERE PTID = " + i.ToString();
con.Open();
SqlCommand com = new SqlCommand(query, con);
reader = com.ExecuteReader();
object[] productDetalis = new object[8];
while (reader.Read())
{
Button b = new Button();
b.Size = new Size(75, 75);
b.Text = reader.GetString(2);
b.Tag = reader.GetValues(productDetalis);
b.Click += new EventHandler(UpdateProductList);
flp.Controls.Add(b);
}
tp.Controls.Add(flp);
i++;
}
catch (System.Data.SqlClient.SqlException ex)
{
string msg = "Error:";
msg += ex.Message;
throw new Exception(msg);
}
finally
{
con.Close();
}
}
}
void UpdateProductList(object sender, EventArgs e)
{
Button b = (Button)sender;
// what should i do??????
}
or if someone can help me to convert the follwing code it is made up by using entites but i want to use sql
private void AddProductsToTab()
{
int i = 1;
foreach (TabPage tp in tabControl1.TabPages)
{
ObjectQuery<TblProduct> filteredProduct = new ObjectQuery<TblProduct>("SELECT VALUE P FROM TblProducts AS P WHERE P.ProductType = " + i.ToString(), posde);
FlowLayoutPanel flp = new FlowLayoutPanel();
flp.Dock = DockStyle.Fill;
foreach (TblProduct tprod in filteredProduct)
{
Button b = new Button();
b.Size = new Size(100, 100);
b.Text = tprod.Description;
b.Tag = tprod;
b.Click += new EventHandler(UpdateProductList);
flp.Controls.Add(b);
}
tp.Controls.Add(flp);
i++;
}
}
void UpdateProductList(object sender, EventArgs e)
{
Button b = (Button)sender;
TblProduct p = (TblProduct)b.Tag;
products.Add(p);
UpdateCustomerInfo(p);
TransactionTotal = TransactionTotal + (decimal)p.Price;
lbProductChoosen.SelectedIndex = lbProductChoosen.Items.Count - 1;
}
private void UpdateCustomerInfo(TblProduct product)
{
string CurrentDescription = product.Description;
string Currentprice = String.Format("{0:c}", product.Price);
string CurrentDescriptionPadded = CurrentDescription.PadRight(15);
txtInfoPanel.Text = CurrentDescriptionPadded + Currentprice;
}