Click here to Skip to main content
15,881,281 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
:((

i want to generate click event of dynamically generated linkbutton more than one linkbutton

my code
 protected void btnecat_Click(object sender, EventArgs e)
    {
        Panel2.Visible = true;

        OleDbCommand cmd = con.CreateCommand();

        cmd.CommandText = "select subcategory1 from subcategory where cateid='1'";

        OleDbDataReader dr = cmd.ExecuteReader();

        while (dr.Read())
        {
            lin = new LinkButton();

            
            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;
        }
    }
</br>


but its not working
Posted
Updated 15-Jun-10 2:11am
v2
Comments
PSK_ 15-Jun-10 7:58am    
Are you getting any error? Can you confirm that your query select "subcategory1 from subcategory where cateid='1'" is returning something?

 
Share this answer
 
U r creating dynamically link button so u have to manually create event handler for that link button

example is given below

lin.Click += new System.EventHandler(lin_Click);



<br />
protected void lin_Click(object sender, EventArgs e)<br />
    {<br />
        LinkButton linkbtn = (LinkButton)sender;<br />
        Response.Write(linkbtn.ID); //get the link button id <br />
//here you can perform operation on link button<br />
      <br />
    }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900