Harish Mohanan
Harish Mohanan

Reputation: 184

Asp Gridview: How Prevent Empty columns from binding?

I have created a Asp GridView with 5 columns. But not always does the sql query return 5 columns, certain times it is 4 and 3 as well. So, when lesser number of columns are returned, I get the following error:-

DataBinding: 'System.Data.DataRowView' does not contain a property with the name 'ExactRate3'

How to prevent this?

Upvotes: 0

Views: 155

Answers (2)

VDWWD
VDWWD

Reputation: 35564

You can make sure the query always return 5 values, even if you select only 3 columns. You can aslo set the value for those dummy columns.

SELECT ExactRate1, ExactRate2, NULL AS ExactRate3, 'emptyString' AS ExactRate4, 0 AS ExactRate5

This way the GridView databinding will find ExactRate3 and not throw an error.

Upvotes: 1

Slobodzyan Taras
Slobodzyan Taras

Reputation: 179

Remove static columns from GridView and set property AutoGenerateColumns='true'

Upvotes: 1

Related Questions