i want to generate click event at runtime of dynamically generated linkbutton my code is:
protected void btnecat_Click(object sender, EventArgs e)
{
OleDbCommand cmd = con.CreateCommand();
cmd.CommandText = "select subcategory1 from subcategory where cateid='1'";
OleDbDataReader dr = cmd.ExecuteReader();
int count = 1;
while (dr.Read())
{
lin = new LinkButton();
//lin.ID = linkbtncat + count.ToString();
lin.ID="lin_"+count.ToString();
lin.Text = dr.GetString(0);
lin.CommandName = "lin" + count.ToString();
lin.CommandArgument = count.ToString();
lin.Click += new EventHandler(lin_Click);
Panel2.Controls.Add(lin);
Panel2.Controls.Add(new LiteralControl("<br>"));
count = count + 1;
}
}
void lin_Click(object sender, EventArgs e)
{
string str1 = ((LinkButton)sender).CommandArgument;
switch (str1)
{
case "1":
tx = lin.Text;
Panel3.Visible = true;
OleDbCommand cm = con.CreateCommand();
cm.CommandText = "select * from itemsale where itemsubcat='tv'";
OleDbDataReader d = cm.ExecuteReader();
while (d.Read())
{
lblitemcode.Text = d.GetString(0);
lblitemname.Text = d.GetString(1);
lblitemcat.Text = d.GetString(2);
lblitemsu.Text = d.GetString(3);
lblcomp.Text = d.GetString(4);
lblrate.Text = d.GetString(5);
}
break;
}
}