473,837 Members | 1,814 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Insert Data Into Table with GridView or Calling Function

1 New Member
Hello,
I am new at this, and have been trying to insert data into a table by using the footer of a gridview (which I dont like) or by using a detials view on the same page that is doing the following:

1) gets query string from url and filters records (works great) via a Details View
2) shows notes that have been added to the record shown in the details view using a grid view, and it filters the data by looking at the ID that is selected in the detailsview. (so Gridview filters by the detiailsview1.s electedvalue) Which works great..
3) I want to add a note that is related to the record by NoteID, so I added another Details view that has insert enabled and as long as I manually type the "DealID" which is not the PK for the table, I can add the note to the record. BUT if I create template controls out of the second detailsview and call a function that gets the selected value of the 1st details view (which populated the textbox correctly) and I hit Insert, nothing happens.

Using VB in visual Studio 2005
I have defaulted the view to insert mode.

Here is the code I use for getting the value to populate the Textbox (Ive tried both GetDeaalID() and GetNoteID() methods defined here which populates the control in the insert mode, but nothing happens when I enter text and click insert on the web form.):

Partial Class CallCenter_Defa ult
Inherits System.Web.UI.P age

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArg s) Handles Me.Load

Dim Username As String = " "
Session("Userna me") = Request.ServerV ariables("Auth_ user")
Label1.Text = Session("Userna me")


End Sub

Protected Function GetDealID()
Dim sDealID As String = ""
sDealID = Request.QuerySt ring("vendor_ID ")
Return sDealID
End Function

Protected Function GetViewID()
Dim sViewID As String = ""
sViewID = DetailsView1.Se lectedValue
Return sViewID
End Function

End Class


_______________ _______________ ________

And Here is the snippet from my DetailsView:

<asp:DetailsVie w ID="DetailsView 4" runat="server" AutoGenerateRow s="False" DataKeyNames="N oteID"
DataSourceID="S qlDataSource1" Height="50px" Width="125px">
<Fields>
<asp:TemplateFi eld HeaderText="Dea lID" SortExpression= "DealID">
<EditItemTempla te>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("DealID") %>'></asp:TextBox>
</EditItemTemplat e>
<InsertItemTemp late>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# GetViewID() %>'></asp:TextBox>
</InsertItemTempl ate>
<ItemTemplate >
<asp:Label ID="Label1" runat="server" Text='<%# Bind("DealID") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateFie ld>
<asp:BoundFie ld DataField="logi n" HeaderText="log in" SortExpression= "login" />
<asp:BoundFie ld DataField="Note " HeaderText="Not e" SortExpression= "Note" />
<asp:CommandFie ld ShowInsertButto n="True" />
</Fields>
</asp:DetailsView >


_______________ _______________ _______________ ________

Here is My Datasource Code:

<asp:SqlDataSou rce ID="SqlDataSour ce1" runat="server" ConnectionStrin g="<%$ ConnectionStrin gs:PCVSQLTestCo nnectionString %>"
DeleteCommand=" DELETE FROM [Notes] WHERE [NoteID] = @NoteID" InsertCommand=" INSERT INTO [Notes] ([DealID], [login], [Note]) VALUES (@DealID, @login, @Note)"
SelectCommand=" SELECT [DealID], [NoteID], [login], [Note] FROM [Notes] WHERE ([DealID] = @DealID)"
UpdateCommand=" UPDATE [Notes] SET [DealID] = @DealID, [login] = @login, [Note] = @Note WHERE [NoteID] = @NoteID">
<DeleteParamete rs>
<asp:Paramete r Name="NoteID" Type="Int32" />
</DeleteParameter s>
<UpdateParamete rs>
<asp:Paramete r Name="DealID" Type="Decimal" />
<asp:Paramete r Name="login" Type="String" />
<asp:Paramete r Name="Note" Type="String" />
<asp:Paramete r Name="NoteID" Type="Int32" />
</UpdateParameter s>
<SelectParamete rs>
<asp:ControlPar ameter ControlID="Deta ilsView1" Name="DealID" PropertyName="S electedValue"
Type="Decimal" />
</SelectParameter s>
<InsertParamete rs>
<asp:Paramete r Name="DealID" Type="Decimal" />
<asp:Paramete r Name="login" Type="String" />
<asp:Paramete r Name="Note" Type="String" />
</InsertParameter s>
</asp:SqlDataSour ce>
Dec 11 '07 #1
0 4068

Sign in to post your reply or Sign up for a free account.

Similar topics

2
13403
by: george | last post by:
This is like the bug from hell. It is kind of hard to explain, so please bear with me. Background Info: SQL Server 7.0, on an NT box, Active Server pages with Javascript, using ADO objects. I'm inserting simple records into a table. But one insert command is placing 2 or 3 records into the table. The 'extra' records, have the same data as the previous insert incident, (except for the timestamp).
10
3407
by: Mike | last post by:
I know this sounds strange but I am at a loss. I am calling a simple funtion that opens a connection to a SQL Server 2000 database and executes an Insert Statement. private void AddMinimunWageStipen(string payrollid,double amount) { System.Data.SqlClient.SqlConnection cn = null; System.Data.SqlClient.SqlCommand cm = null;
7
14826
by: | last post by:
Hello, Does anyone have an idea on how I can filter the data in the gridview control that was returned by an sql query? I have a gridview that works fine when I populate it with data. Now I want to look at that data and filter it based on what is in it. I know that this could have been done with data sets and data views in asp.net 1.1 but how is this done now in asp.net 2.0?
1
3702
by: JayD | last post by:
Here is the problem: Using asp.net 2.0 to create a web app with standard master table gridview and child detailsview with insert capability. SQL Server 2000 database on the backend. Using Visual Web Developer for front-end development. I want to insert new records in detailsview based on selected gridview record. All the fields in "INSERT" mode are blank, which is okay EXCEPT that I want the child ID to be that of the selected...
8
18095
by: Greg Lyles | last post by:
Hi all, I'm trying to develop an ASP.NET 2.0 website and am running into some real problems with what I thought would be a relatively simple thing to do. In a nutshell, I'm stuck on trying to display data in a "GridView" which is tied to an "ObjectDataSource". In turn, this ObjectDatasource gets it's data from a strongly-typed business object within my code.
1
2814
by: =?Utf-8?B?SGFycnkgS2Vjaw==?= | last post by:
I have a GridView that I dynamically add columns to in code. The way that my code is written, everything works properly if I use GridView.Columns.Add to simply add the columns to the end of the collection. However, if I use GridView.Columns.Insert to inject the columns in the middle of the existing columns, I see lots of exceptions when I page the GridView, because certain controls contained within the grid are mysteriously absent? Can...
1
6138
by: sheenaa | last post by:
Hello Members, I m creating my application forms in ASP.Net 2005 C# using the backend SQL Server 2005. What i have used on forms :: ? On my first form i have used some label,textboxs,dropdownlists,radiobutton and checkbox asp standard controls. On the click event of the command button the data gets stored into the database. I have created the stored procedures for the insert,update,delete. I have...
1
1539
by: Anilsg | last post by:
Hi all, I have the DropDownList in the FormView,inside InsertTemplateField The data is binded in run time to it in codebehind page,FOr the First time the page is loaded the DropdownList is not empty. when i click on the insert Link the data should be displayed in the gridView (Which is below the formview), But when i click on the Insert link the data is displayed in the gridView, But the DropdownList is empty. Here is the...
0
1221
by: Anilsg | last post by:
Hi all, I have the DropDownList in the FormView,inside InsertTemplateField The data is binded in run time to it in codebehind page,FOr the First time the page is loaded the DropdownList is not empty. when i click on the insert Link the data should be displayed in the gridView (Which is below the formview), But when i click on the Insert link the data is displayed in the gridView, But the DropdownList is empty.
0
9846
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10580
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10277
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9413
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7817
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7007
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5674
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
4052
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3126
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.