user133371
user133371

Reputation: 321

Why do I need to bind GridView on every postback to make click events from columns to work

Ok, i have a gridview and on page load, i dynamically add a column to it that contains a link control. this link control has a onclick event associated with it so that when its clicked, i want to do some processing. Now I have noticed that if I just bind the grid the first time (i.e. if(!IsPostBack) and have enableviewstate for the grid to be true, clicking the link in that column, doesnt trigger the onclick event. But if I bind the grid on every postback, everything seems to be working..does anyone know the reasoning behind it?

Upvotes: 0

Views: 1780

Answers (2)

Vinay
Vinay

Reputation:

May be creating the row Id solves your problem. Check out this link and the post marked as answer.

http://forums.asp.net/p/1471128/3408069.aspx#3408069

Regards Vinay

Upvotes: 0

CAbbott
CAbbott

Reputation: 8098

It happens because you're dynamically adding the column, so on every postback the column has to be created. What you may want to do is to look at Creating a Custom Column.

Upvotes: 2

Related Questions