1

I am binding a repeater to XmlDataSource, binding an image source with a node value like below

<img src="<%# XPath("a:tags/a:tag[contains(@namespace, 'second_image')]", nsmgrdc).ToString() %>"
alt="<%# XPath("a:title",nsmgrdc)%>" />

but sometimes my XML doesn't have this node so i receive an error

Object reference not set to an instance of an object.

is there a way i can check or do try, catch on the ItemTemplate level

Miroo
  • 795
  • 3
  • 13
  • 35

1 Answers1

0

It's because of calling ToString method on null object. Simply use XPath("a:tags/a:tag[contains(@namespace, 'second_image')]", nsmgrdc) without calling ToString.

Kirill Polishchuk
  • 54,804
  • 11
  • 122
  • 125