0

I have a collection of records, each record has an ID and a description. Now in my formview I have 8 textboxes and I want each text box to hold description of each record.

So if I do this

Text='<%# Eval("Record[0].Description") %>' />

This gives an error, any other way to do it?

Also can I do it in the markup, or do I need to do it in code behind, under databound method for the formview?

Thanks..

1
  • what error? if you just want to show record repeater is better option Commented May 6, 2013 at 18:18

2 Answers 2

1

FormView is not meant for showing List of Data.

If you have a List of Data, then you should use GridView or ListView.

Bind your FormView with a datasource having single record and then directly Eval the fields of the datasource.

i.e. do this:

<asp:FormView ID="FormView1" runat="server" DataSourceID="SqlDataSourceId">  
    <ItemTemplate>
        <asp:TextBox id="txtDescription" 
                     Text='<%# Eval("Description") %>' />

        <asp:TextBox id="txtName" 
                     Text='<%# Eval("Name") %>' />


         ..
     </ItemTemplate>
 </asp:FormView>

so basically, your FormView should contain different DataField and it should be bound to a DataSource having just one Item.

Sign up to request clarification or add additional context in comments.

8 Comments

Thanks a lot for reply. But here is my situation - I have a formview with edit template and a category in the formview has 8 textboxes. The data of those texboxes is in a collection of 8 records. Now when I go into the edit mode of formview, I get the collection of those 8 records, How do I populate those 8 texboxes with their values, so that a user can make change, and save the data as well??
your situation is still not clear to me though. See you bind each field of the formView with one record only. if you have placed 8 textboxes inside your formView, you must bind them with 8 different datafields
yeah, I guess I will break my collection into 8 different data fields, may not be the best way to do it. But it should work.
you should use ListView. its much simpler. both its edit template and insert template. anyway, you can accept this as an answer if it helped you
So you mean, using listview within formview and when I save the form, I save the listview as well?
|
0

You could use a repeater inside:

<asp:repeater ID="rep" runat="server" DataSource='<%# Eval("Record") &>'>
    <ItemTemplate>
        <asp:textbox id="txt" runat="server" Text='<%# Eval("Description") &>' />
    </ItemTemplate>
</asp:repeater>

In the repeater you will bind to your outer datasource, inside the repeater your datacontext is the record

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.