-1

Hi,

I have the following code:

<asp:FormView ID="myFormView" runat="server" SkinID="DetailsFormview">
            <ItemTemplate>
                <table width="400">
                    <tr>
                        <td align="right">
                            <b>This is the label: </b>
                        </td>
                        <td align="left">
                            <asp:Label ID="myLabel" Text="Label Text"
runat="server" />
                        </td>
                    </tr>
                </table>
            </ItemTemplate>
        </asp:FormView>

And in the code behind (VB.NET):

Protected Sub BindFormView()
    Dim myLabel As Label = myFormView.FindControl("myLabel")
    myLabel.Text = AnotherLabel.Text
End Sub

However, myLabel is always nothing. As you see, my formview has only an ItemTemplate. I tried setting hte DefaultMode to ReadOnly but I still have the same problem: myLabel = Nothing!

Any suggestion of what is wrong?

Thanks,

Ana

2
Contributors
1
Reply
4
Views
8 Years
Discussion Span
Last Post by Ramesh S
0

FormView is basically used to display the values of a single record from a data source.

The controls in the ItemTemplate will be rendered only after binding a data source to the FormView control.

In the BindFormView() method, you didn't bind any data source to the FormView control. Therefore myFormView.FindControl("myLabel") returns always nothing.

Try after data binding to the FormView. It will return the Label control.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.