I had a grid view with the DataSourceId property is set to a SqlDataSource control. Also it have a RowDataBound event bounded to have custom data formatting. Then I noticed that the RowDataBound is getting fired twice, as if it binding data twice.

The reason for that behavior I figured out after some hours of debugging. The reason was I have some code that set the column headers which assign language specific header titles on Page_Load() event. When you alter the column specific properties after data binding through a Data Source control, it always tries to get the data set again from the source. But this happen only when there is a change in the newly assigned data.

Because I had some pages doing the same thing, but they were not having this issue. Then I realized that if the newly assigned data differs from what exists in the GridView, only then it tries to call for another data fetch.

This won’t happen if you had created the data set separately, and assign it into the DataSource property.


Hope I have saved someones time.


One thought on “GridView bound by SqlDataSource, RowDataBound event gets called twice

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s