简体   繁体   English

使用SqlDataSource将数据从FormView发送到我的数据库

[英]Sending data from FormView to my database using SqlDataSource

I have multiple FormViews within my ASP.NET application which have different controls within them such as text box's and drop down lists. 我的ASP.NET应用程序中有多个FormView,其中有不同的控件,例如文本框和下拉列表。

Firstly in my database I have a list of users with lots of details. 首先,在我的数据库中,我列出了具有很多详细信息的用户。 In my application I have a text box where I can search for a user and it will populate one of my form views using the SqlDataSource, however my other form views do not get automatically populated when searched and this is the section that the user will fill in and press submit to then submit all of the data including the pre populated data back to the database. 在我的应用程序中,我有一个文本框,可以在其中搜索用户,它将使用SqlDataSource填充我的一个表单视图,但是搜索时不会自动填充我的其他表单视图,这是用户将填写的部分并按提交以将所有数据(包括预先填充的数据)提交回数据库。

I am not sure where to start for this and would appreciate it if someone can either give me some examples or point me in the correct direction as to how to do this. 我不确定从哪里开始,如果有人可以给我一些例子或为我指出正确的方向,我将不胜感激。

Here is an example of one of my FormViews: 这是我的一个FormViews的示例:

            <div class="compliant-details">
            <asp:FormView runat="server" DataSourceID="ds_complaints" CssClass="complient-details-first-section" DefaultMode="Insert">
                <InsertItemTemplate>
                    <div class="compliant-details-method">
                        <label class="applicationfont">Method:</label>
                        <asp:DropDownList class="smallinputbox" runat="server" ID="ddl_compliant_details_method" DataSourceID="ds_compliantmethod"
                            DataTextField="ComplaintMethod" DataValueField="ComplaintMethodId" AppendDataBoundItems="true">
                            <asp:ListItem Value="0" Text="<Please Select>" />
                        </asp:DropDownList>
                    </div>
                    <div class="compliant-details-type">
                        <label class="applicationfont">Type:</label>
                        <asp:DropDownList class="smallinputbox ddl" runat="server" ID="ddl_compliant_details_type" DataSourceID="ds_types"
                            DataTextField="TypeName" DataValueField="TypeId" AppendDataBoundItems="true">
                        </asp:DropDownList>
                    </div>
                    <div class="compliant-details-status">
                        <label class="applicationfont">Status:</label>
                        <asp:DropDownList class="smallinputbox" runat="server" ID="ddl_compliant_details_status" DataSourceID="ds_status"
                            DataTextField="Status" DataValueField="StatusId" AppendDataBoundItems="true">
                            <asp:ListItem Value="0" Text="<Please Select>" />
                        </asp:DropDownList>
                    </div>
                    <div class="compliant-details-catagory">
                        <label class="applicationfont">Catagory:</label>
                        <asp:DropDownList class="smallinputbox" runat="server" ID="ddl_compliant_details_catagory" DataSourceID="ds_category"
                            DataTextField="Category" DataValueField="Categoryid" AppendDataBoundItems="true">
                            <asp:ListItem Value="0" Text="<Please Select>" />
                        </asp:DropDownList>
                    </div>
                    <div class="compliant-details-recorded-by">
                        <label class="applicationfont">Recorded By:</label>
                        <asp:DropDownList class="smallinputbox" runat="server" ID="ddl_compliant_details_recorded_by" DataSourceID="ds_agents"
                            DataTextField="AgentName" DataValueField="AgentId" AppendDataBoundItems="true" />
                    </div>
                    <div class="compliant-details-handeld-by">
                        <label class="applicationfont">Handeld By:</label>
                        <asp:DropDownList class="smallinputbox" runat="server" ID="ddl_compliant_details_handald_by" readonly="readonly" DataSourceID="ds_agents"
                            DataTextField="AgentName" DataValueField="AgentId" AppendDataBoundItems="true" />
                    </div>
                    <div class="compliant-details-rfc-sent">
                        <label class="applicationfont">RFC Sent:</label>
                        <div class="compliant-details-rfc-rb">
                            <asp:RadioButton runat="server" ID="rb_compliant_details_rfc_sent_yes" Text="Yes" CssClass="applicationfont" GroupName="rfcsent" />
                            <asp:RadioButton runat="server" ID="rb_compliant_details_rfc_sent_no" Text="No" CssClass="applicationfont" GroupName="rfcsent" />
                        </div>
                    </div>
                    <div class="compliant-details-accepted-by-client">
                        <label class="applicationfont">Accepted By Client:</label>
                        <div class="compliant-details-accepted-rb">
                            <asp:RadioButton runat="server" ID="rb_compliant_details_accepted_by_client_yes" Text="Yes" CssClass="applicationfont" />
                            <asp:RadioButton runat="server" ID="rb_compliant_details_accepted_by_client_no" Text="No" CssClass="applicationfont" />
                        </div>
                    </div>
                </InsertItemTemplate>
            </asp:FormView>

Why don't you just use the "Edit Template" on the same FormView? 您为什么不只在同一FormView上使用“编辑模板”?

  • User searches. 用户搜索。
  • FormView populates. FormView填充。
  • User can press "Edit" which will change the form mode to Edit. 用户可以按“编辑”,这会将表格模式更改为“编辑”。
  • User presses "SUBMIT" and then the changes are sent to the database. 用户按下“提交”,然后将更改发送到数据库。

Why have more than one FormView? 为什么有多个FormView?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM