Solved

Sending hidden values when inserting new records with detailsview

Posted on 2006-10-24
9
232 Views
Last Modified: 2008-02-01
I have a Detailsview that is filled with 4 data table fields (linkId, link_descr, link, articleId).

LinkId is the id column and gets a new ID automatically on insert. The problem is to send the articleId that is stored in a sessionID to the database on insert.

I want to be able to insert new texts for link_descr and link but keep the session("articleID") and insert that into the same record.

Thanks for help.
0
Comment
Question by:peternordberg
  • 5
  • 4
9 Comments
 
LVL 96

Expert Comment

by:Bob Learned
ID: 17798304
Are you asking how to get the new ID after the insert is executed?  Retrieving autonumber/identity values?

Bob
0
 

Author Comment

by:peternordberg
ID: 17798327
No. I want the equivalent to the old <input type="hidden" name="articleID" value=<%=articleId%>">. I want to be able to store an already existing value that is stored in a session variable back to the database on insert, using detailsview.
0
 

Author Comment

by:peternordberg
ID: 17798411
Bob, did yoou understand what I said or was it just confusing?
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 96

Expert Comment

by:Bob Learned
ID: 17798429
What is the DetailsView bound to?

Bob
0
 

Author Comment

by:peternordberg
ID: 17798433
a sqlDatasource
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 17798443
What does the SqlDataSource declaration look like?

Bob
0
 

Author Comment

by:peternordberg
ID: 17798464
<asp:SqlDataSource ID="sqlEdit" runat="server" ConnectionString="<%$ ConnectionStrings:skipperConn %>"
        DeleteCommand="DELETE FROM [links] WHERE [linkID] = @linkID" InsertCommand="INSERT INTO [links] ([link_descr], [link]) VALUES (@link_descr, @link)"
        SelectCommand="SELECT [linkID], [link_descr], [link], [artikelID] FROM [links] WHERE ([linkID] = @linkID)"
        UpdateCommand="UPDATE [links] SET [link_descr] = @link_descr, [link] = @link WHERE [linkID] = @linkID">
        <DeleteParameters>
            <asp:Parameter Name="linkID" Type="Int32" />
        </DeleteParameters>
        <UpdateParameters>
            <asp:Parameter Name="link_descr" Type="String" />
            <asp:Parameter Name="link" Type="String" />
            <asp:Parameter Name="linkID" Type="Int32" />
        </UpdateParameters>
        <SelectParameters>
            <asp:ControlParameter ControlID="GridLinks" Name="linkID" PropertyName="SelectedValue"
                Type="Int32" />
        </SelectParameters>
        <InsertParameters>
            <asp:Parameter Name="link_descr" Type="String" />
            <asp:Parameter Name="link" Type="String" />
        </InsertParameters>
    </asp:SqlDataSource>
0
 
LVL 96

Accepted Solution

by:
Bob Learned earned 125 total points
ID: 17799589
When doing an insert, you can bind the InsertParameters to a control with the ControlParameters, like you did with the SelectParameters.

Here is an example:

http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.sqldatasource.updateparameters.aspx

<asp:SqlDataSource
          id="SqlDataSource1"
          runat="server"
          ConnectionString="<%$ ConnectionStrings:MyNorthwind%>"
          SelectCommand="SELECT EmployeeID, LastName, Address FROM Employees"
          UpdateCommand="UPDATE Employees SET Address=@Address WHERE EmployeeID=@EmployeeID">
          <UpdateParameters>
              <asp:ControlParameter Name="Address" ControlId="TextBox1" PropertyName="Text"/>
              <asp:ControlParameter Name="EmployeeID" ControlId="DropDownList1" PropertyName="SelectedValue"/>
          </UpdateParameters>
      </asp:SqlDataSource>

Bob
0
 

Author Comment

by:peternordberg
ID: 17801357
Of course! I figured that out when you mentioned the sqldatasource. Thanks for help again.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
asp.net mvc5 6 30
VS 2015 is giving [No relevant source lines] 2 38
why JSON Array data not binding on Model ASP.NET ? 1 28
Validating textboxes in red square borders. 2 33
Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

756 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question