IIF and FieldCount Property of Container.DataIte,

G

George

All,

I have a data gid and I want the text of and ItemTemplate
asp:Label Field to be the value of a column from the DataReader which
the grid is bound to. HOWEVER, I need to do it dynamically as the
datareader may contain between 3 and 7 fields. This, I attempt to use
an IIF statement and only display a value from the datareader if there
are enough columns in the datareader. The line of code looks as
follows:

<asp:Label id=lblfield1 runat="server" Text='<%#
DataBinder.Eval(Container.DataItem.fieldcount > 2,
Container.DataItem.GetString(2), "") %>'>


When I run this, I expect to get the value of the third column
(getString(2)) from the DataReader if a third column exists
(Fieldcount > 2)

When i attempt to run this, I get the following error message:


The following error occurred: 5 - DataBinder.Eval: 'System.Boolean'
does not contain a property with the name Partial Payment Received *.

FYI 'Partial Payment Received *.' is the value of the third column in
the datareader.

Any ideas???

Thanks
George
 
M

[MSFT]

Hi George,

You may try following approach:

<ItemTemplate>
<asp:Label id=lblfield1 runat="server" Text='<%#
ShowLabel(Container.DataItem) %>'>
</asp:Label>
</ItemTemplate>


In code behind:

public string ShowLabel(Object drv)
{
System.Data.Common.DbDataRecord dd=(System.Data.Common.DbDataRecord)drv;


if (dd.FieldCount >2)
{
return dd.GetString(1) ;
}
else
{
return "";
}
}


Hope this help.

Luke
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,050
Latest member
AngelS122

Latest Threads

Top