Solved

Sending hidden values when inserting new records with detailsview

Posted on 2006-10-24
9
230 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
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…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
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 …

772 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