Link to home
Start Free TrialLog in
Avatar of sbornstein2
sbornstein2

asked on

ASP.Net/C# - checking if a DataBinder is null?

Hello all.,  I have an ASPX page that uses a web control grid.  I have the following in my code behind for the web control.

 object roleValue = DataBinder.Eval(DataItem, "ContributorRole");
 
If my grid on my ASPX page datasource is set to "". which I have to do to get my grid to show headers etc.  It is a telerik control and they told me I have to set it to "" if its null.  Then the above gets an error cant insert the control from the grid.  I tried seeing if I could say != null but that won't work.  There is a GetDataItem(container, out bool) but I couldnt figure out how to do that or it was coming back null all the  time even with a valid datasource.  The error only happens when there is no data in my grid its datasource is set to "".  Thanks all
Avatar of Ted Bouskill
Ted Bouskill
Flag of Canada image


Convert.IsDBNull(DataBinder.Eval(DataItem, "ContributorRole")) ? "" : (String)DataBinder.Eval(DataItem, "ContributorRole")

Open in new window

Avatar of sbornstein2
sbornstein2

ASKER

the error I get is:

"DataBinding: 'Telerik.Web.UI.GridInsertionObject' does not contain a property with the name 'ContributorRole'."

That is when it hits the Convert.IsDBNull piece
ASKER CERTIFIED SOLUTION
Avatar of Ted Bouskill
Ted Bouskill
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial