troubleshooting Question

passing data from Select Statement to Insert using FormView

Avatar of mgit
mgit asked on
ASPASP.NET
2 Comments1 Solution581 ViewsLast Modified:
I'm using FromView - please see the attached. I'm retrieving Acct_ID among other data from the DB. In the Insert statement I would like to use the same Acct_ID i got earlier but my text box doesn't get populated with it. How can I get it accomplished in FormView?
Thanks for your help.
Mark
<asp:FormView ID="frmNew_Agreement" DataSourceID="sqlDataSource1"  
  runat="server" DataKeyNames="acct_name" AllowPaging="true" PagerSettings-Mode="Numeric" EnableViewState="true" >
  
  <ItemTemplate>
  <table>
  <tr>
  <td class="td_l">
  Account ID: 
  </td>
  <td class="td_r">
  <asp:Label ID="lblAcct_Id" runat="server" Text='<%# Bind("acct_id") %>' ></asp:Label>
  </td>
  </tr>
  <tr>
  <td class="td_l">
  Agreement ID: 
  </td>
  <td class="td_r">
  <asp:Label ID="lblAgreement_Number" runat="server" Text='<%# Bind("agreement_id") %>' ></asp:Label>
  </td>
  </tr>
  <tr>
  <td class="td_l">
  Account Name:
  </td>
  <td class="td_r">
   <asp:label ID="lblAcct_Name" runat="server" Text='<%# Bind("acct_name") %>'></asp:label>
  </td>
  </tr>
  <tr>
  <td class="td_l">
  Account Active:
  </td>
  <td class="td_r">
   <asp:Label runat="server" ID="lblAcct_Active" Text='<%# Bind("acct_active") %>'></asp:Label>
  </td>
  </tr>
  <tr>
  <td class="td_l">
  Account Manager:
  </td>
  <td class="td_r">
  <asp:Label runat="server" ID="lblAcct_Mgr" Text='<%# Eval("acct_mgr") %>'></asp:Label>
  </td>
  </tr>
  
  <tr>
  <td colspan="2">
  <asp:Button ID="btnNew" Text="New" CommandName="New" runat="Server" ></asp:Button>
  <asp:Button ID="btnCancel" Text="Cancel" CommandName="Cancel" runat="Server" />
  
  </td>
  </tr>
  </table>
  
  </ItemTemplate>
  
  
  <InsertItemTemplate>
  <table width="500" >
  <tr valign="top">
  <td class="td_l">
  Account ID:</td>
  <td class="td_r" valign="top">
  <asp:Label runat="server" ID="lblAcct_ID" AssociatedControlID="txtAcct_ID" Text="Account ID:" Width="150" ></asp:Label>
  <asp:TextBox runat="Server" ID="txtAcct_ID" Text='<%# Bind("acct_id") %>' Width="250" BackColor="#e6e7e8" ></asp:TextBox>
  <asp:RequiredFieldValidator ID="Validator1" ControlToValidate="txtAcct_id" runat="server" Text="Required!" ></asp:RequiredFieldValidator> 
  </td>
  </tr>
  <tr valign="top">
  <td class="td_l">
  Agreement ID:</td>
  <td class="td_r">
  <asp:TextBox runat="server" ID="txtAgreement_ID" Text='<%# Bind("agreement_id") %>' Width="250" BackColor="#e6e7e8"></asp:TextBox>
  <asp:RequiredFieldValidator ID="Validator2" ControlToValidate="txtAgreement_id" runat="server" Text="Required!" ></asp:RequiredFieldValidator>  
  </td>
  </tr>
  <tr>
  <td colspan="2">
  <asp:Button ID="btnInsert" Text="Insert" CommandName="Insert" runat="server" CausesValidation="true"></asp:Button>
  <asp:Button ID="btnCancel" Text="Cancel" CommandName="Cancel" runat="server" CausesValidation="false"></asp:Button>
  </td>
  </tr>
  </table>
  </InsertItemTemplate>
  
  </asp:FormView>
  
 <asp:SqlDataSource runat="server" ID="sqlDataSource1" 
 ConnectionString="<%$ connectionstrings:conString %>" InsertCommandType="storedProcedure"
 SelectCommand="SELECT * from vwNew_Agreement" FilterExpression="Acct_Name = '{0}'" 
 InsertCommand="spNew_Agreement" >
 
  <FilterParameters>
  <asp:ControlParameter Name="Acct_Name" ControlID="txtAcct_Name" />
  </FilterParameters>
  <InsertParameters>
  <asp:Parameter Name="acct_id" Type="string" />
  <asp:Parameter Name="agreement_id" Type="string" />
  
  </InsertParameters>
  
  </asp:SqlDataSource>
ASKER CERTIFIED SOLUTION
mgit

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 2 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 2 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros