Solved

Sending hidden values when inserting new records with detailsview

Posted on 2006-10-24
9
231 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
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

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…
I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

856 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