D
Dave Moore
Hey all,
I'm binding a DataList to a custom collection of image objects
and it seems to work really well, albeit with this minor hitch...
As soon as I try to use the DataBinder.Eval to get the value of my Height
property, I get an Invalid Cast Specified.
If I leave the Height out, or hard code it to say "70" (which just so
happens to be the value of the Height property at the time of binding)
It works fine.
Is there something I should be taking into special account when attempting
to supply a value for the Height and Width properties for the image control?
Thanks in advance.... here are my supporting classes...
/// <summary>
/// Class representing a barcode image
/// </summary>
public class BarcodeImage
{
/// <summary>
/// Image height
/// </summary>
public int Height
{
get { return _height; }
}
private int _height;
/// <summary>
/// Image width
/// </summary>
public int Width
{
get { return _width; }
}
private int _width;
/// <summary>
/// Url to the image
/// </summary>
public string Url
{
get { return _url; }
}
private string _url;
/// <summary>
/// Used for alt text; the original value, before barcoding
/// </summary>
public string RawValue
{
get { return _rawValue; }
}
private string _rawValue;
/// <summary>
/// Constructor
/// </summary>
private BarcodeImage() {}
/// <summary>
/// Constructor
/// </summary>
/// <param name="height"></param>
/// <param name="width"></param>
/// <param name="url"></param>
/// <param name="rawValue"></param>
public BarcodeImage (int height, int width, string url, string rawValue)
{
this._height = height;
this._width = width;
this._url = url;
this._rawValue = rawValue;
}
}
/// <summary>
/// Collection skeleton
/// Derive from CollectionBase in order to implement
/// ICollection and IEnumerable
/// </summary>
public class BarcodeImageCollection : System.Collections.CollectionBase
{
//strongly typed accessor
public BarcodeImage this[int index]
{
get { return (BarcodeImage) this.List[index]; }
set
{
//warning, this is not for adding, but for reassigning
//this will throw an exception if the index does not already
//exist. Use Add(object) to add to collection
this.List[index] = value;
}
}
/// <summary>
/// Method to add a BarcodeImage to the collection
/// </summary>
/// <param name="barcodeImage">the BarcodeImage to add</param>
public void Add(BarcodeImage barcodeImage)
{
this.List.Add(barcodeImage);
}
}
I'm binding a DataList to a custom collection of image objects
and it seems to work really well, albeit with this minor hitch...
As soon as I try to use the DataBinder.Eval to get the value of my Height
property, I get an Invalid Cast Specified.
If I leave the Height out, or hard code it to say "70" (which just so
happens to be the value of the Height property at the time of binding)
It works fine.
Is there something I should be taking into special account when attempting
to supply a value for the Height and Width properties for the image control?
Thanks in advance.... here are my supporting classes...
/// <summary>
/// Class representing a barcode image
/// </summary>
public class BarcodeImage
{
/// <summary>
/// Image height
/// </summary>
public int Height
{
get { return _height; }
}
private int _height;
/// <summary>
/// Image width
/// </summary>
public int Width
{
get { return _width; }
}
private int _width;
/// <summary>
/// Url to the image
/// </summary>
public string Url
{
get { return _url; }
}
private string _url;
/// <summary>
/// Used for alt text; the original value, before barcoding
/// </summary>
public string RawValue
{
get { return _rawValue; }
}
private string _rawValue;
/// <summary>
/// Constructor
/// </summary>
private BarcodeImage() {}
/// <summary>
/// Constructor
/// </summary>
/// <param name="height"></param>
/// <param name="width"></param>
/// <param name="url"></param>
/// <param name="rawValue"></param>
public BarcodeImage (int height, int width, string url, string rawValue)
{
this._height = height;
this._width = width;
this._url = url;
this._rawValue = rawValue;
}
}
/// <summary>
/// Collection skeleton
/// Derive from CollectionBase in order to implement
/// ICollection and IEnumerable
/// </summary>
public class BarcodeImageCollection : System.Collections.CollectionBase
{
//strongly typed accessor
public BarcodeImage this[int index]
{
get { return (BarcodeImage) this.List[index]; }
set
{
//warning, this is not for adding, but for reassigning
//this will throw an exception if the index does not already
//exist. Use Add(object) to add to collection
this.List[index] = value;
}
}
/// <summary>
/// Method to add a BarcodeImage to the collection
/// </summary>
/// <param name="barcodeImage">the BarcodeImage to add</param>
public void Add(BarcodeImage barcodeImage)
{
this.List.Add(barcodeImage);
}
}