简体   繁体   中英

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.

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.

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:

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

  • User searches.
  • FormView populates.
  • 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?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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