By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,330 Members | 1,074 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,330 IT Pros & Developers. It's quick & easy.

Insert Data Into Table with GridView or Calling Function

P: 1
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
Share this question for a faster answer!
Share on Google+

Post your reply

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