Solved

Sending hidden values when inserting new records with detailsview

Posted on 2006-10-24
9
225 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
Comment Utility
Are you asking how to get the new ID after the insert is executed?  Retrieving autonumber/identity values?

Bob
0
 

Author Comment

by:peternordberg
Comment Utility
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
Comment Utility
Bob, did yoou understand what I said or was it just confusing?
0
 
LVL 96

Expert Comment

by:Bob Learned
Comment Utility
What is the DetailsView bound to?

Bob
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:peternordberg
Comment Utility
a sqlDatasource
0
 
LVL 96

Expert Comment

by:Bob Learned
Comment Utility
What does the SqlDataSource declaration look like?

Bob
0
 

Author Comment

by:peternordberg
Comment Utility
<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
Comment Utility
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
Comment Utility
Of course! I figured that out when you mentioned the sqldatasource. Thanks for help again.
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

771 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now