Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have a grid in asp.net, inside the asp.net i am binding data as linkbutton when clicking on link button I need to call a method in code behind. the attached event is not woking in my code. how i can solve this?

my code is similar like this,

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            LinkButton link = new LinkButton();
            link.Text = e.Row.Cells[0].Text;
            link.CommandArgument = "Hello";
            link.Click += new EventHandler(this.onLinkClick);  
            e.Row.Cells[0].Controls.Add(link);
        }

    }

    protected void onLinkClick(object sender, EventArgs e)
    {
        LinkButton btn = (LinkButton)(sender);
        string value = btn.CommandArgument;
        TextBox1.Text=value;
    }  
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
209 views
Welcome To Ask or Share your Answers For Others

1 Answer

You have to call the function that binds the source to the GridView everytime in the Page Load

ex.

protected void Page_Load(object sender, EventArgs e)
{
     PopulateGridView();
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...