views:

106

answers:

1

Hi

i have a FormView, it renders fields from a SQLServer database but also much static text specific to the database value I get. I dont know if this can be done in the code behind and put all this in a function . I put it in my formview

<ItemTemplate>

<% If Eval("Feature1") = "Yes" Then %>

<%# Eval("Username") %>

A lot of text

<% elseIf Eval("Feature1") = "No" Then %>

<%# Eval("Username") %>

A lot of different text

<% End If %>

</ItemTemplate>

If I do the code above I get error message:

Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control. Can this be done within the formview?

Many thanks for your help.

A: 

Your if logic should be in the code behind, in the databound event of your control.

Each row will fire this event, and you can then edit how the row should look based on the data.

protected void FormView1_DataBound(object sender, EventArgs e)
{

}
Clarence Klopfstein
Hi Thaks. I knew this. I just wanted to ask if there was a better way to present the heavy text involved in code behind.
VirtualGirl
IMO, this is the best and preferred way. No reason to recreate the wheel.
Clarence Klopfstein