Solved

Sending hidden values when inserting new records with detailsview

Posted on 2006-10-24
9
228 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
 
LVL 96

Expert Comment

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

Bob
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
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.…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

896 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

11 Experts available now in Live!

Get 1:1 Help Now