English 中文(简体)
asp.net绑定问题
原标题:asp.net binding problem

我的代码中包含以下属性

public string Firstname {get;set;}

当我想将其绑定到某个文本框时,我会执行以下操作:

<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>
最佳回答

它将在页面加载中绑定,但您必须告诉它在标记或代码中绑定到什么。你没有说你在哪里或如何存储你的数据,听起来你正在尝试插入新的数据,所以。。。

Here is a tutorial on the sqldatasource. SQL Datasource Tutorial

Here is a turorial on the formview: Formview Tutorial

这是我做的一个简单的。。。(注意:我没有测试下面的代码,所以如果我忘记了一些东西,我很抱歉,但这应该会给你一个好的开始)。

 <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>    

编辑:修复了教程的链接。。。我没有意识到原始链接没有显示表单视图上的信息。

问题回答

暂无回答




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签