StrataFrame Forum

Custom field, WebBBS and AspxGridView - Column is not exist

http://forum.strataframe.net/Topic18110.aspx

By Chan - 7/27/2008

Hi,

I have created custom property in my BO, attach it to WebBBS and bind to AspxGridView. I hit error that "Column 'myCustomField' does not exist in System.Data.DataView".



Any ideas? Urgent!



Thank you
By Bill Cunnien - 7/28/2008

Make sure that your FieldPropertyDescriptors have been defined in your BO, like this:


protected override FieldPropertyDescriptor[] GetCustomBindablePropertyDescriptors()
{
   
return new FieldPropertyDescriptor[]
    {
       
new ReflectionPropertyDescriptor("myCustomField", typeof(MyBO))
   
};
}
By Trent L. Taylor - 7/28/2008

The only reason that you would get this error is:

  1. You are attempting to access the BO like this: MyBO.Item("MyField") and you do not have a descriptor.  Even still, you would want to pull it from the table like this: MyBO.CurrentRow.Item("MyField")
  2. You do not have a type descriptor as mentioned by Juan
By ChanKK - 7/28/2008

Hi,

I encounter error message when I try to bind a DropDownList in a GridView to a BO Custom Bindable Property.

My Custom Bindable Property in BO:

protected override FieldPropertyDescriptor[] GetCustomBindablePropertyDescriptors()

{

return new FieldPropertyDescriptor[]

{

new ReflectionPropertyDescriptor("ApproverCode", typeof(RouteGroupBO))

};

}

[Browsable(false),

BusinessFieldDisplayInEditor(),

Description("ApproverCode"),

DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]

public System.String ApproverCode

{

get

{

_approver = new ApproverBO();

Guid id = this.CurrentRow["ApproverId"] == DBNull.Value ? Guid.Empty : (Guid)this.CurrentRow["ApproverId"];

_approver.FillById(id);

if (_approver.MoveFirst())

{

return _approver.ApproverCode;

}

else

{

return string.Empty;

}

}

}

ERROR MESSAGE AT ASPX PAGE (DEBUG MODE):

<ItemTemplate>
   <asp:Label ID="lblApproverCode" runat="server"
   Text='<%# Bind("ApproverCode") %>'></asp:Label>
</ItemTemplate>

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

 

However, it simply run fine with this.MyBoInstance.MyCustomField. Help...

By Trent L. Taylor - 7/29/2008

This looks to be a very simple problem.  Your code is a bit confusing as you are creating a new BO instance inside of the BO you are referencing.  So this is a bit confusing.  Secondly, you are seeking inside of the property itself, which again, could cause all types of problems and is definitely not recommended.  Your code should look more like this:

public System.String ApproverCode

{
get
{
Guid id = this.CurrentRow["ApproverId"] == DBNull.Value ? Guid.Empty : (Guid)this.CurrentRow["ApproverId"];

if (id != null)
{
 //-- Obviously you will want to call another internal method.  But you should get the idea.  Calling
 //-- a scalar method would be faster and cleaner than your other code.
 return (string)Me.ExecuteScalar("SELECT code FROM WhateverTable WHERE mycriteria = @mycritera);

}
else
{
 return string.Empty;
}}}

If you can't get it to work, then post a sample that reproduces the problem instead of posting code snippetts.  Thanks.