I am in need of help above I am trying to create a formview with textboxes and two dropdownlist thats coming from two different sql tables, the user will pick from each table and the information will populate in HoldingDock tbl. The problem I am facing is the behind code I'm writing in c# and totally lost...
First. The user will have to be able to edit the form (dropdownlist) or perhap delete the weight entirely from the customerID. I am not sure on how to write the c code.
Second. How do I get it to whole its value when I do a search on the customer id. During my testing phase I did a search on the customer id and the dropdown value was not the same one that was select the first time, but the textboxes were correct.

Any help will be appreciate to get me started.

Thank you

<form id="form1" runat="server">
    <div>
     </div>
    <asp:FormView ID="FormView1" DataSourceID="Custds" DefaultMode="Insert" 
        AllowPaging="true" runat="server" Width="542px">
     <itemtemplate>
          <table width="100%" cellpadding="5" border="0">
         <col width="25%" valign="top" align="right">
         <tr>
            <td>Date:</td>
            <td><b><%# Eval("Date")%></b></td></tr>
         <tr>
            <td>Customer Name:</td>
            <td><b><%# Eval("CustomerName")%></b></td></tr>
         <tr>
            <td>Customer Number:</td>
            <td><b><%# Eval("CustomerNumber")%></b></td></tr>
         <tr>
            <td>COD:</td>
            <td><b><%# Eval("COD")%></b></td></tr>
         <tr>
            <td>Pickup:</td>
            <td><b><%# Eval("Pickup")%></b></td></tr>
         <tr>
            <td>Weight:</td>
            <td><b><%# Eval("Weightrange")%></b></td></tr>   
         <tr>
            <td colspan="2">
               <asp:button id="EditButton" text="Edit"  commandname="Edit" runat="server" />
            </td></tr>               
         </table>
       </itemtemplate>
     
     <EditItemTemplate>
     <table>
     <tr><td>Date: <asp:TextBox ID="txtDate" runat="server" Text='<%# Bind("Date") %>' /> </td></tr>
     <tr>
     <td>Customer Name: 
        <asp:TextBox ID="txtCustName" runat="server" Text='<%# Bind("CustomerName") %>' /></td>
     <td>Customer Number:    
        <asp:DropDownList ID="CustNbrDropdownlist" runat="server" 
            DataSourceID="DropDownNumber" SelectedValue='<%# Bind("CustomerNumber") %>'
            DataTextField="CustNumber" DataValueField="CustID">
        </asp:DropDownList>
     </td>
     </tr>
     </table> 
      <table>
     <tr><td>COD: <asp:TextBox ID="txt" runat="server" Text='<%# Bind("COD") %>' /> </td></tr>
     <tr><td>Pickup: <asp:TextBox ID="txtpick" runat="server" Text='<%# Bind("Pickup") %>' /> </td></tr>
     <tr>
     <td>Weight:    
        <asp:DropDownList ID="WeightDropDownList" runat="server" 
            DataSourceID="DropDownWeight" SelectedValue='<%# Bind("Weightrange") %>'
            DataTextField="weightrange" DataValueField="weightID">
        </asp:DropDownList>
     </td>
     </tr>
     </table>    
    
     <table> 
        <tr>
            <td colspan="2">
               <asp:button id="updatebutton" text="Update"  commandname="Update" runat="server" />
               &nbsp;
               <asp:button id="cancelbutton" text="Cancel" commandname="Cancel" runat="server" />
            </td>
       </tr> 
      </table>      
     </EditItemTemplate>
    
     <InsertItemTemplate>
     <table>
     <tr><td>Date: <asp:TextBox ID="txtDate" runat="server" Text='<%# Bind("Date") %>' /> </td></tr>
     <tr>
     <td>Customer Name: 
        <asp:TextBox ID="txtCustName" runat="server" Text='<%# Bind("CustomerName") %>' /></td>
     <td>Customer Number:    
        <asp:DropDownList ID="CustNbrDropdownlist" runat="server" 
            DataSourceID="DropDownNumber" SelectedValue='<%# Bind("CustomerNumber") %>'
            DataTextField="CustNumber" DataValueField="CustID">
        </asp:DropDownList>
     </td>
     </tr>
     </table> 
      <table>
     <tr><td>COD: <asp:TextBox ID="txt" runat="server" Text='<%# Bind("COD") %>' /> </td></tr>
     <tr><td>Pickup: <asp:TextBox ID="txtpick" runat="server" Text='<%# Bind("Pickup") %>' /> </td></tr>
     <tr>
     <td>Weight:    
        <asp:DropDownList ID="WeightDropDownList" runat="server" 
            DataSourceID="DropDownWeight" SelectedValue='<%# Bind("Weightrange") %>'
            DataTextField="weightrange" DataValueField="weightID">
        </asp:DropDownList>
     </td>
     </tr>
     </table>    
       <table> 
        <tr>
            <td colspan="2">
               <asp:button id="insertbutton" text="Insert"  commandname="Insert" runat="server" />
             </td>
       </tr> 
      </table>    
         <asp:sqldatasource ID="DropDownNumber" runat="server" connectionstring="<%$ ConnectionStrings:ReceivngDock %>" 
         SelectCommand="Select [CustNumber] From [Customer_Val_tbl]"></asp:sqldatasource>
 
         <asp:sqldatasource ID="DropDownWeight" runat="server" connectionstring="<%$ ConnectionStrings:ReceivngDock %>" 
         SelectCommand="Select [weightrange] From [Weight_tbl]"></asp:sqldatasource>
      </InsertItemTemplate>
     </asp:FormView>
    
    <asp:sqldatasource id="Custds" runat="server" 
      selectcommand="SELECT Date, CustomerName, CustomerNumber, COD, Pickup, Weightrange FROM HoldingDock"
      insertcommand="INSERT HoldingDock (Date, CustomerName, CustomerNumber, COD, Pickup, Weightrange) VALUES (@Date, @CustomerName, @CustomerNumber, @COD, @Pickup, @Weightrange)"
      updatecommand="UPDATE HoldingDock SET 
         Date=@Date, CustomerName=@CustomerName, CustomerNumber=@CustomerNumber, COD=@COD, Pickup=@Pickup, Weightrange=@Weightrange 
         WHERE OrderID=@OrderID"
      connectionstring="<%$ ConnectionStrings:ReceivngDock %>" />


    
    </form>
<asp:DropDownList ID="CustNbrDropdownlist" runat="server"             DataSourceID="DropDownNumber" SelectedValue='<%# Bind("CustomerNumber") %>'            DataTextField="CustNumber" DataValueField="CustID"  AppendDataBoundItems="True" 
                 AutoPostBack="True">
                 <asp:ListItem Value="" Selected="True">(None)</asp:ListItem>       </asp:DropDownList>



<asp:DropDownList ID="WeightDropDownList" runat="server"             DataSourceID="DropDownWeight" SelectedValue='<%# Bind("Weightrange") %>'            DataTextField="weightrange" DataValueField="weightID" AppendDataBoundItems="True" AutoPostBack="True">
<asp:ListItem Value="" Selected="True">(None)</asp:ListItem>       </asp:DropDownList>




//Code aspx.cs===================
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

protected void FormView1_ItemInserting(object sender, FormViewInsertEventArgs e)
    {
        e.Values["CustomerNumber"] = ((DropDownList)FormView2.Row.FindControl("CustNbrDropdownlist")).SelectedValue;

e.Values["Weightrange"] = ((DropDownList)FormView2.Row.FindControl("WeightDropDownList")).SelectedValue;

}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.