473,326 Members | 2,438 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Insert Data Into Table with GridView or Calling Function

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.selectedvalue) 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_Default
Inherits System.Web.UI.Page

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

Dim Username As String = " "
Session("Username") = Request.ServerVariables("Auth_user")
Label1.Text = Session("Username")


End Sub

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

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

End Class


______________________________________

And Here is the snippet from my DetailsView:

<asp:DetailsView ID="DetailsView4" runat="server" AutoGenerateRows="False" DataKeyNames="NoteID"
DataSourceID="SqlDataSource1" Height="50px" Width="125px">
<Fields>
<asp:TemplateField HeaderText="DealID" SortExpression="DealID">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("DealID") %>'></asp:TextBox>
</EditItemTemplate>
<InsertItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# GetViewID() %>'></asp:TextBox>
</InsertItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("DealID") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="login" HeaderText="login" SortExpression="login" />
<asp:BoundField DataField="Note" HeaderText="Note" SortExpression="Note" />
<asp:CommandField ShowInsertButton="True" />
</Fields>
</asp:DetailsView>


__________________________________________________ ___

Here is My Datasource Code:

<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:PCVSQLTestConnectionString %>"
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">
<DeleteParameters>
<asp:Parameter Name="NoteID" Type="Int32" />
</DeleteParameters>
<UpdateParameters>
<asp:Parameter Name="DealID" Type="Decimal" />
<asp:Parameter Name="login" Type="String" />
<asp:Parameter Name="Note" Type="String" />
<asp:Parameter Name="NoteID" Type="Int32" />
</UpdateParameters>
<SelectParameters>
<asp:ControlParameter ControlID="DetailsView1" Name="DealID" PropertyName="SelectedValue"
Type="Decimal" />
</SelectParameters>
<InsertParameters>
<asp:Parameter Name="DealID" Type="Decimal" />
<asp:Parameter Name="login" Type="String" />
<asp:Parameter Name="Note" Type="String" />
</InsertParameters>
</asp:SqlDataSource>
Dec 11 '07 #1
0 4013

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

Similar topics

2
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. ...
10
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...
7
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...
1
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...
8
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...
1
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...
1
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...
1
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...
0
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...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.