0

I have in my code behind the following property

public string Firstname {get;set;}

when I want to bind it to some textbox I do the following:

<asp:TextBox runat="server" ID="txtFirstname" Text='<%# Bind("Firstname") %>'/>

then I want value put in this textbox to be set in my Firstname property (because I want to process it e.g. save this value) in my presenter. Why it doesn't work? EDIT Here is the aspx

<formview runat="server" ID="myFormView">
                <p>Firstname <asp:TextBox ID="txtFirstName"  runat="server" Text='<%# Eval("Firstname") %>' /></p>
                <p>Lastname <asp:TextBox ID="txtLastName" runat="server" /></p>
                <input type="button" title="send" runat="server" id="btnSend" />
            </formview>
8
  • Please see stackoverflow.com/questions/1997735/… and also stackoverflow.com/questions/2871404/… Commented Oct 25, 2010 at 20:16
  • I post everything needed. No other things are set in code behind (except a method that is called when submit button is clicked) Commented Oct 25, 2010 at 20:18
  • Are you calling Page.DataBind() in Page_Load? Commented Oct 25, 2010 at 20:23
  • We need more info. Are other controls binding as expected? Is this happening in a postback? Is the textbox in formview? If so is the formview in the proper mode? etc. Some markup may help. Commented Oct 25, 2010 at 20:30
  • You should probably show us the actual mark up and code that you are using...that formview doesn't have an ID or datasource. If it had an ID that would lead me to beleive you are manually setting the datasrouce in the code which may be part of problem depending on how you are doing it. If you don't want to post secret info change the Ids and hide only the confidential info. Commented Oct 25, 2010 at 20:47

1 Answer 1

0

It will bind in the page load but you have to tell it what to bind to in mark up or in code. You didn't say where or how you're storing your data and it sounds like you are trying to insert new data so...

Here is a tutorial on the sqldatasource. SQL Datasource Tutorial

Here is a turorial on the formview: Formview Tutorial

Here is a simple one I whipped up...(NOTE: I did not test the below code, so if I forgot somehting my apologies, but it should give you a good start).

 <asp:SqlDataSource ID="SqlDataSource1" 
    runat="server" 
    ConnectionString="Connection string for your database here." 
    SelectCommand="SELECT FirstName, LastName FROM YourTable"
    >
</asp:SqlDataSource>

    <asp:FormView ID="frmYourForm" DefaultMode="Insert" runat="server" DataSourceID="SqlDataSource1">
        <EditItemTemplate>
            <asp:TextBox ID="txtFirstName" runat="server" Text='<%# Bind("FirstName") %>'></asp:TextBox>
            <br />
            <asp:TextBox ID="txtLastName" runat="server" Text='<%# Bind("LastName") %>'></asp:TextBox>
            <asp:LinkButton ID="LinkButton1" CommandName="Update" runat="server">Update</asp:LinkButton>
        </EditItemTemplate>
        <InsertItemTemplate>
            <asp:TextBox ID="txtFirstName" runat="server" Text='<%# Bind("FirstName") %>'></asp:TextBox>
            <br />
            <asp:TextBox ID="txtLastName" runat="server" Text='<%# Bind("LastName") %>'></asp:TextBox>
            <asp:LinkButton ID="LinkButton1" CommandName="Insert" runat="server">Insert</asp:LinkButton>
            </InsertItemTemplate>
    </asp:FormView>    

EDIT: Fixed the links to the tutorials...I didn't realize the orginal link didn't show info on the formview.

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

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.