InsertCommand into Header Template - asp.net

Trying to insert three textboxes into the header of a gridview and with a button execute an "INSERT INTO" into the database.
In my online server database: idt is int, datetime is varchar, and col1,col2,col3 are numeric.
<asp:SqlDataSource
id="SqlDataSource1"
ConnectionString="<%$ ConnectionStrings:connone %>"
SelectCommand="SELECT * FROM [test];"
InsertCommand="INSERT INTO [test] [datetime],[col1],[col2],[col3] VALUES #datetime,#col1,#col2,#col3;"
runat="server">
<InsertParameters>
<asp:Parameter Name="datetime" Type="String" />
<asp:Parameter Name="col1" Type="Double" />
<asp:Parameter Name="col2" Type="Double" />
<asp:Parameter Name="col3" Type="Double" />
</InsertParameters>
</asp:SqlDataSource>
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
SqlDataSource1.InsertParameters("#datetime").DefaultValue = DateTime.Now.ToString()
SqlDataSource1.InsertParameters("#col1").DefaultValue = CType(GridView1.HeaderRow.FindControl("TextBoxHeadercol1"), TextBox).Text
SqlDataSource1.InsertParameters("#col2").DefaultValue = CType(GridView1.HeaderRow.FindControl("TextBoxHeadercol2"), TextBox).Text
SqlDataSource1.InsertParameters("#col3").DefaultValue = CType(GridView1.HeaderRow.FindControl("TextBoxHeadercol3"), TextBox).Text
SqlDataSource1.Insert()
End Sub
<asp:GridView ID="GridView1"
runat="server"
DataSourceID="SqlDataSource1"
AutoGenerateColumns="False"
DataKeyNames="idt">
<Columns>
<asp:BoundField DataField="idt" HeaderText="idt" Readonly="true" SortExpression="idt" />
<asp:BoundField DataField="datetime" HeaderText="datetime" SortExpression="datetime" />
<asp:TemplateField SortExpression="col1">
<HeaderTemplate>
<asp:TextBox ID="TextBoxHeadercol1" text="col1" runat="server" MaxLength="40" />
</HeaderTemplate>
</asp:TemplateField>
<asp:TemplateField SortExpression="col2">
<HeaderTemplate>
<asp:TextBox ID="TextBoxHeadercol2" text="col2" runat="server" MaxLength="40" />
</HeaderTemplate>
</asp:TemplateField>
<asp:TemplateField SortExpression="col3">
<HeaderTemplate>
<asp:TextBox ID="TextBoxHeadercol3" text="col3" runat="server" MaxLength="40" />
</HeaderTemplate>
</asp:TemplateField>
</asp:GridView>

I suggest to remove "#" in InsertParameters as follows:
SqlDataSource1.InsertParameters("col1").DefaultValue =
((TextBox)GridView1.HeaderRow.FindControl("TextBoxHeadercol1")).Text;
this should work.

Related

Stored Procedure not working with bulk update to rows bound to gridview

I'm using a grid view to update all rows in the grid at the same time. This code is working on another page perfectly. The difference now is that I'm calling a stored procedure since I have 3 tables I need to update. I receive no errors but nothing is getting updated in the tables. I believe that the parameters are not getting passed through properly.
<asp:GridView ID="GridView1" runat="server" BackColor="White" BorderColor="#999999" BorderStyle="Solid" BorderWidth="1px" CellPadding="3"
DataSourceID="SqlDataSource1" ForeColor="Black" GridLines="Vertical" AutoGenerateColumns="False" DataKeyNames="CUST_ORDER_ID">
<AlternatingRowStyle BackColor="#CCCCCC" />
<Columns>
<asp:BoundField DataField="CUST_ORDER_ID" HeaderText="ORDER_ID" SortExpression="CUST_ORDER_ID">
<ItemStyle Width="50px"></ItemStyle>
</asp:BoundField>
<asp:BoundField DataField="NAME" HeaderText="NAME" ReadOnly="True" SortExpression="NAME">
<ItemStyle Width="400px"></ItemStyle>
</asp:BoundField>
<asp:BoundField DataField="ORDERDATE" HeaderText="ORDER DATE" DataFormatString="{0:d}" ReadOnly="True" SortExpression="ORDERDATE">
<ItemStyle Width="100px"></ItemStyle>
</asp:BoundField>
<asp:BoundField DataField="DESIREDSHIPDATE" HeaderText="DESIRED SHIP DATE" SortExpression="DESIREDSHIPDATE" DataFormatString="{0:d}" ReadOnly="True" ItemStyle-Width="100" >
<ItemStyle Width="100px"></ItemStyle>
</asp:BoundField>
<asp:BoundField DataField="PROMISEDATE" HeaderText="PROMISE DATE" SortExpression="PROMISEDATE" DataFormatString="{0:d}" ReadOnly="True" ItemStyle-Width="100">
<ItemStyle Width="100px"></ItemStyle>
</asp:BoundField>
<asp:BoundField DataField="PROMISEDELDATE" HeaderText="DELIVERY DATE" SortExpression="PROMISEDELDATE" DataFormatString="{0:d}" ReadOnly="True" ItemStyle-Width="100" >
<ItemStyle Width="100px"></ItemStyle>
</asp:BoundField>
<asp:TemplateField HeaderText="TRIP_ORDER" SortExpression="TRIP_ORDER" ItemStyle-Width="500">
<EditItemTemplate>
<asp:textbox ID="TextBox3" runat="server" Text='<%# Bind("TRIP_ORDER") %>'></asp:textbox>
</EditItemTemplate>
<ItemTemplate>
<asp:TextBox ID="TripOrderTextBox" runat="server" Text='<%# Bind("TRIP_ORDER") %>' Width="25px"></asp:TextBox>
</ItemTemplate>
<ItemStyle Width="25px"></ItemStyle>
</asp:TemplateField>
<asp:BoundField DataField="ORDER_LINE_SUMMARY" HeaderText="ORDER LINE SUMMARY" SortExpression="ORDER_LINE_SUMMARY">
<ItemStyle Width="50px"></ItemStyle>
</asp:BoundField>
<asp:TemplateField HeaderText="JOB_DEL_NOTES" SortExpression="JOB_DEL_NOTES" ItemStyle-Width="500">
<EditItemTemplate>
<asp:textbox ID="TextBox1" runat="server" Text='<%# Bind("JOB_DEL_NOTES") %>'></asp:textbox>
</EditItemTemplate>
<ItemTemplate>
<asp:TextBox ID="JobDelNotesTextBox" runat="server" Text='<%# Bind("JOB_DEL_NOTES") %>' Rows="3" TextMode="MultiLine" Width="500px" onkeypress="return this.value.length<=79" MaxLength="80"></asp:TextBox>
</ItemTemplate>
<ItemStyle Width="500px"></ItemStyle>
</asp:TemplateField>
<asp:TemplateField HeaderText="ORDER_DEL_NOTES" SortExpression="ORDER_DEL_NOTES" ItemStyle-Width="500">
<EditItemTemplate>
<asp:textbox ID="TextBox2" runat="server" Text='<%# Bind("ORDER_DEL_NOTES") %>'></asp:textbox>
</EditItemTemplate>
<ItemTemplate>
<asp:TextBox ID="OrderDelNotesTextBox" runat="server" Text='<%# Bind("ORDER_DEL_NOTES") %>' Rows="3" TextMode="MultiLine" Width="500px" onkeypress="return this.value.length<=79" MaxLength="80"></asp:TextBox>
</ItemTemplate>
<ItemStyle Width="500px"></ItemStyle>
</asp:TemplateField>
</Columns>
<FooterStyle BackColor="#CCCCCC" />
<HeaderStyle BackColor="Black" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#000099" Font-Bold="True" ForeColor="White" />
<SortedAscendingCellStyle BackColor="#F1F1F1" />
<SortedAscendingHeaderStyle BackColor="#808080" />
<SortedDescendingCellStyle BackColor="#CAC9C9" />
<SortedDescendingHeaderStyle BackColor="#383838" />
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" CancelSelectOnNullParameter="false" ConnectionString="<%$ ConnectionStrings:ConnectionStringTest %>"
ProviderName="<%$ ConnectionStrings:ConnectionStringTest.ProviderName %>"
SelectCommandType="StoredProcedure" SelectCommand="CM_GET_SCHEDULED_ORDERS"
UpdateCommandType="StoredProcedure" UpdateCommand="CM_SP_UPDATE_TRIP">
<SelectParameters>
<asp:QueryStringParameter Name="DELIVERY_DATE" DbType="DateTime" Direction="Input" QueryStringField="PROMISE_DEL_DATE" DefaultValue="" />
<asp:Parameter Name="UPDATE_TRIP" DefaultValue="YES" Type="String" />
</SelectParameters>
<UpdateParameters>
<asp:Parameter Name="CUST_ORDER_ID" DefaultValue="" Type="String" Direction="Input" />
<asp:Parameter Name="ORDER_LINE_SUMMARY" Type="String" Direction="Input" />
<asp:Parameter Name="TRIP_ORDER" DefaultValue="" Type="String" Direction="Input"/>
<asp:Parameter Name="PROMISEDELDATE" Defaultvalue="" Type="datetime" Direction="Input"/>
<asp:Parameter Name="JOB_DEL_NOTES" Type="String" Direction="Input"/>
<asp:Parameter Name="ORDER_DEL_NOTES" Type="String" Direction="Input"/>
</UpdateParameters>
</asp:SqlDataSource>
My code behind:
Imports Microsoft.VisualBasic
Imports System.Data
Imports System.Configuration
Imports System.Data.SqlClient
Public Class UpdateTrip
Inherits System.Web.UI.Page
Private tableCopied As Boolean = False
Private originalDataTable As System.Data.DataTable
Protected Sub Page_load(sender As Object, e As EventArgs) Handles Me.Load
If Not IsPostBack Then
SetDateTextBox.Text = Request.QueryString("PROMISE_DEL_DATE")
End If
End Sub
Protected Sub btnRedirect_Click(sender As Object, e As EventArgs)
Response.Redirect("~/UpdateTrip.aspx?PROMISE_DEL_DATE=" + SetDateTextBox.Text)
End Sub
Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound
If e.Row.RowType = DataControlRowType.DataRow Then
If Not tableCopied Then
originalDataTable = CType(e.Row.DataItem, System.Data.DataRowView).Row.Table.Copy()
ViewState("originalValuesDataTable") = originalDataTable
tableCopied = True
End If
End If
End Sub
Protected Sub UpdateButton_Click(ByVal sender As Object, ByVal e As EventArgs) Handles UpdateTrip.Click
originalDataTable = CType(ViewState("originalValuesDataTable"), System.Data.DataTable)
For Each r As GridViewRow In GridView1.Rows
'If IsRowModified(r) Then GridView1.UpdateRow(r.RowIndex, False)
GridView1.UpdateRow(r.RowIndex, False)
Next
' Rebind the Grid to repopulate the original values table.
'tableCopied = False
'GridView1.DataBind()
Response.Redirect("~/UpdateTrip.aspx?PROMISE_DEL_DATE=" + SetDateTextBox.Text)
End Sub
'Protected Function IsRowModified(ByVal r As GridViewRow) As Boolean
' Dim currentID As String
' Dim currentTripOrder As String
' Dim currentJobDelNotes As String
' Dim currentOrderDelNotes As String
' currentID = Convert.ToInt32(GridView1.DataKeys(r.RowIndex).Value)
' currentTripOrder = CType(r.FindControl("TripOrderTextBox"), TextBox).Text
' currentJobDelNotes = CType(r.FindControl("JobDelNotesTextBox"), TextBox).Text
' currentOrderDelNotes = CType(r.FindControl("OrderDelNotesTextBox"), TextBox).Text
' Dim row As System.Data.DataRow =
' originalDataTable.Select(String.Format("cust_order_id = {0}", currentID))(0)
' If Not currentTripOrder.Equals(row("Trip_order").ToString()) Then Return True
' If Not currentJobDelNotes.Equals(row("Job_Del_Notes").ToString()) Then Return True
' If Not currentOrderDelNotes.Equals(row("Order_Del_Notes").ToString()) Then Return True
' Return False
'End Function
Protected Sub Calendar1_SelectionChanged(sender As Object, e As EventArgs) Handles Calendar1.SelectionChanged
SetDateTextBox_PopupControlExtender.Commit(Calendar1.SelectedDate)
End Sub
End Class
Stored Procedure
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Michael Mueller>
-- Create date: <8/3/2016>
-- Description: <update multiple tables for the trip order. customer_order. cust_order_line, cust_address>
-- =============================================
ALTER PROCEDURE [dbo].[CM_SP_UPDATE_TRIP]
-- Add the parameters for the stored procedure here
#CUST_ORDER_ID varchar(15),
#ORDER_LINE_SUMMARY VARCHAR(MAX),
#TRIP_ORDER VARCHAR(3),
#PROMISE_DEL_DATE DATETIME,
#JOB_DEL_NOTES varchar(80),
#ORDER_DEL_NOTES VARCHAR(80)
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- update cust_adress with job delivery notes
UPDATE CUST_ADDRESS
SET USER_4 = #JOB_DEL_NOTES
FROM dbo.CUSTOMER_ORDER INNER JOIN
dbo.CUST_ADDRESS ON dbo.CUSTOMER_ORDER.CUSTOMER_ID = dbo.CUST_ADDRESS.CUSTOMER_ID AND
dbo.CUSTOMER_ORDER.SHIPTO_ID = dbo.CUST_ADDRESS.SHIPTO_ID
WHERE (dbo.CUSTOMER_ORDER.ID = #CUST_ORDER_ID)
-- update customer_order with order delivery notes
UPDATE CUSTOMER_ORDER
SET USER_5 = #ORDER_DEL_NOTES
WHERE ID = #CUST_ORDER_ID
-- update cust_order_line with trip_order information
IF #ORDER_LINE_SUMMARY = 'ALL LINES'
BEGIN
UPDATE CUST_ORDER_LINE
SET USER_4 = #TRIP_ORDER
WHERE CUST_ORDER_ID = #CUST_ORDER_ID
END
ELSE -- ONLY SPECIFIC LINES OF ORDER GET UPDATED
BEGIN
UPDATE CUST_ORDER_LINE
SET USER_4 = #TRIP_ORDER
WHERE CUST_ORDER_ID = #CUST_ORDER_ID AND PROMISE_DEL_DATE = #PROMISE_DEL_DATE
END
I figured out the main problem. Using Sql Server Profile I could see that only the binding fields are getting passed to the stored procedure. The other values were null. I created ItemTemplates for the remaining parameters.

Filling GridView Based on DropDownList selected Value (vb.net)

I have a drop down list that has inventory material groups, and I would like there to be a way that when I select a different group, the grid view loads the materials for that group. I'm a little confused on how to accomplish this...
ASPX
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:Design_Construction_V2ConnectionString %>" ProviderName="<%$ ConnectionStrings:Design_Construction_V2ConnectionString.ProviderName %>" SelectCommand="SELECT [UnitPriceInfo], [groupNumber], [itemDescription], [CrossTieType], [AFEFunctionCode], [AFECode], [unitType], [unitPrice] FROM [itemsList_]" FilterExpression="groupNumber = {0}">
<FilterParameters>
<asp:ControlParameter Name="groupNumber" ControlID="ddlMaterials" PropertyName="SelectedValue" Type="Int32" DefaultValue="" />
</FilterParameters>
</asp:SqlDataSource>
<asp:DropDownList runat="server" ID="ddlMaterials"></asp:DropDownList>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource1" EmptyDataText="There are no data records to display.">
<Columns>
<asp:BoundField DataField="UnitPriceInfo" HeaderText="UnitPriceInfo" SortExpression="UnitPriceInfo" />
<asp:BoundField DataField="groupNumber" HeaderText="groupNumber" SortExpression="groupNumber" />
<asp:BoundField DataField="itemDescription" HeaderText="itemDescription" SortExpression="itemDescription" />
<asp:BoundField DataField="CrossTieType" HeaderText="CrossTieType" SortExpression="CrossTieType" />
<asp:BoundField DataField="AFEFunctionCode" HeaderText="AFEFunctionCode" SortExpression="AFEFunctionCode" />
<asp:BoundField DataField="AFECode" HeaderText="AFECode" SortExpression="AFECode" />
<asp:BoundField DataField="unitType" HeaderText="unitType" SortExpression="unitType" />
<asp:BoundField DataField="unitPrice" HeaderText="unitPrice" SortExpression="unitPrice" />
</Columns>
</asp:GridView>
CODEBEHIND
Private Sub ddlMaterials_Load(sender As Object, e As EventArgs) Handles ddlMaterials.Load
If Not IsPostBack Then
Dim db As New DesignConstructionDataContext
Dim materials = (From m In db.Estimate_Groups
Where (m.BigGroup = "Materials")
Select m.groupName)
ddlMaterials.DataSource = materials
ddlMaterials.DataBind()
End If
End Sub
Private Sub ddlMaterials_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ddlMaterials.SelectedIndexChanged
End Sub
Change FilterParameters to SelectParameters. In where clause use this - where groupNumber = #groupNumber. So changed aspx will be like following.
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:Design_Construction_V2ConnectionString %>" ProviderName="<%$ ConnectionStrings:Design_Construction_V2ConnectionString.ProviderName %>" SelectCommand="SELECT [UnitPriceInfo], [groupNumber], [itemDescription], [CrossTieType], [AFEFunctionCode], [AFECode], [unitType], [unitPrice] FROM [itemsList_] where groupNumber = #groupNumber">
<SelectParameters>
<asp:ControlParameter Name="groupNumber" ControlID="ddlMaterials" PropertyName="SelectedValue" Type="Int32" DefaultValue="" />
</SelectParameters>
</asp:SqlDataSource>

Pass a session variable to filterParameter in ASP.Net

I am working in ASP.Net. I am attempting to pass a session variable to a gridview control. When I remove the session variable parameter, the dropdownlist I am using to feed the gridview works correctly. When I add the session variable, it shows everything.
Here is my code behind for the page load event (I am using VB.net):
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
Dim ScreenerID As Int32
Dim intS As Int32
Session("ScreenerID") = 20
intS = CType(Session.Item("ScreenerID"), Int32)
End Sub
My ASP.Net code is as follows:
<%# Page Title="Home Page" Language="VB" AutoEventWireup="true" CodeBehind="Default.aspx.vb" Inherits="SAP._Default" %>
<%# Register assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" tagprefix="cc1" %>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>Screening Portal</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<cc1:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
</cc1:ToolkitScriptManager>
<cc1:TabContainer ID="TabContainer1" runat="server" ActiveTabIndex="0">
<cc1:TabPanel ID="TabPanel1" runat="server" HeaderText="Screening">
<ContentTemplate>
<asp:Label ID="Label2" runat="server" Text="Pull For Screening "></asp:Label>
<asp:DropDownList ID="DropDownList1" runat="server"><asp:ListItem>10</asp:ListItem>
<asp:ListItem>20</asp:ListItem>
</asp:DropDownList>
<asp:Button ID="Button1" runat="server" Text="Add Applicants" />
<asp:Label ID="Label3" runat="server" Text="Choose Campus: "></asp:Label>
<asp:DropDownList ID="DropDownList2" runat="server" AutoPostBack="True" OnSelectedIndexChanged="DropDownList2_SelectedIndexChanged">
<asp:ListItem Text="All" Value=""></asp:ListItem>
<asp:ListItem>CRC</asp:ListItem>
<asp:ListItem>GHS</asp:ListItem>
<asp:ListItem>STL</asp:ListItem>
<asp:ListItem>WPH</asp:ListItem>
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:ScreenerView %>" ProviderName="<%$ ConnectionStrings:ScreenerView.ProviderName %>"
SelectCommand="SELECT [ScreenerID], [LEGAL_FNAME], [LEGAL_LNAME], [APPL_PERSON_ID], [AAMC_ID], [GENDER], [URM], [RecMCAT], [SciGPA], [LEGAL_RES_STATE_CD], [PullDate], [First] FROM [vw_Screener]"
FilterExpression="ScreenerID = {0} AND First='{1}'">
<FilterParameters>
<asp:Parameter Name="intS" Type="int32" />
<asp:ControlParameter ControlID="DropDownList2" PropertyName="SelectedValue" Type="String" DefaultValue=""/>
</FilterParameters>
</asp:SqlDataSource>
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False" DataSourceID="SqlDataSource1" CellPadding="4" ForeColor="#333333" GridLines="None">
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:BoundField DataField="ScreenerID" HeaderText="ScreenerID" SortExpression="ScreenerID" Visible="False"></asp:BoundField>
<asp:BoundField DataField="LEGAL_FNAME" HeaderText="First Name" SortExpression="LEGAL_FNAME" />
<asp:BoundField DataField="LEGAL_LNAME" HeaderText="Last Name" SortExpression="LEGAL_LNAME" />
<asp:BoundField DataField="APPL_PERSON_ID" HeaderText="APPL_PERSON_ID" SortExpression="APPL_PERSON_ID" Visible="False" />
<asp:BoundField DataField="AAMC_ID" HeaderText="AAMC" SortExpression="AAMC_ID" />
<asp:BoundField DataField="GENDER" HeaderText="Gender" SortExpression="GENDER" />
<asp:BoundField DataField="URM" HeaderText="URM" SortExpression="URM" />
<asp:BoundField DataField="RecMCAT" HeaderText="MCAT" SortExpression="RecMCAT" />
<asp:BoundField DataField="SciGPA" HeaderText="Sci. GPA" SortExpression="SciGPA" />
<asp:BoundField DataField="LEGAL_RES_STATE_CD" HeaderText="State" SortExpression="LEGAL_RES_STATE_CD" />
<asp:BoundField DataField="PullDate" HeaderText="Date Pulled" DataFormatString = "{0:d}" SortExpression="PullDate" />
<asp:BoundField DataField="First" HeaderText="First Choice CC" SortExpression="First" />
</Columns>
<EditRowStyle BackColor="#2461BF" />
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#EFF3FB" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#F5F7FB" />
<SortedAscendingHeaderStyle BackColor="#6D95E1" />
<SortedDescendingCellStyle BackColor="#E9EBEF" />
<SortedDescendingHeaderStyle BackColor="#4870BE" />
</asp:GridView>
</ContentTemplate>
</cc1:TabPanel>
<cc1:TabPanel ID="TabPanel2" runat="server" HeaderText="Query">
<ContentTemplate>
<asp:Label ID="Label1" runat="server" Text="Search "></asp:Label><asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</ContentTemplate>
</cc1:TabPanel>
<cc1:TabPanel ID="TabPanel3" runat="server" HeaderText="Manage Invitations">
<ContentTemplate>
</ContentTemplate>
</cc1:TabPanel>
<cc1:TabPanel ID="TabPanel4" runat="server" HeaderText="Reports">
<ContentTemplate>
</ContentTemplate>
</cc1:TabPanel>
<cc1:TabPanel ID="TabPanel5" runat="server" HeaderText="Admin">
<ContentTemplate>
</ContentTemplate>
</cc1:TabPanel>
</cc1:TabContainer>
<br />
</div>
</form>
</body>
</html>
I imagine I am doing something simple that needs a quick fix, but it is beyond me. Thank you.
Since intS doesn’t change much, why don’t you feed it into the select statement instead of applying a filter parameter? what do you think?
ASPX SqlDataSource1:
SelectCommand="SELECT [ScreenerID], [LEGAL_FNAME], [LEGAL_LNAME],
[APPL_PERSON_ID], [AAMC_ID], [GENDER], [URM], [RecMCAT], [SciGPA], [LEGAL_RES_STATE_CD],
[PullDate], [First]
FROM [vw_Screener]
WHERE [First] = #First" <-- Notice the WHERE Clause
Remove <asp:Parameter Name="intS" Type="int32" /> from FilterParameters and then change your FilterExpression to:
FilterExpression="First='{0}'"
But you must add [First] as a parameter in the SelectParameters section like so:
<SelectParameters>
<asp:Parameter Name="First" />
</SelectParameters>
VB.NET Code-Behind:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
Dim ScreenerID As Int32
Dim intS As Int32
Session("ScreenerID") = 20
intS = CType(Session.Item("ScreenerID"), Int32)
SqlDataSource1.SelectParameters.Add("#First ",intS) '<-- Here is where we set intS
End Sub

Update is not working on GridView

Hey guys,
I have a GridView which is binded to SqlDataSource, everything works fine, just update does not works, i am calling stored procedure, and all parameters and its dataTypes are proper, actually none of the events work on that update button, i tried to change the CommandName to "Change" and created OnCommand Event, and wrote Response Message in the code. but nothing happens on the update button, cancel button works fine, and also delete works, there is just a problem with update, even if the procedure has some issue atleast event should raised, i even checked in Sql Profiler, but the update procedure never hits Sql Server 2008...
But when i remove SqlDataSource then everything works fine also the update command with same stored procedure.
Please help me out for this, i have stuck here badly
<asp:GridView ID="GridView1" runat="server" DataSourceID="SqlDataSource1" AutoGenerateColumns="False"
CellPadding="4" DataKeyNames="Title" EnableModelValidation="True"
ForeColor="#333333" GridLines="None"
ShowFooter="True" Width="950" AllowPaging="true" PageSize="10">
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
<Columns>
<asp:TemplateField HeaderText="Title">
<ItemTemplate>
<%# Eval("Title") %>
</ItemTemplate>
<EditItemTemplate>
<asp:Label ID="txtEditTitle" runat="server" Text='<%# Bind("Title") %>'></asp:Label>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Quote">
<ItemTemplate>
<%# Eval("Quote") %>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtEditQuote" runat="server" Text='<%# Bind("Quote") %>'></asp:TextBox>
</EditItemTemplate>
</asp:TemplateField >
<asp:TemplateField HeaderText="Quote Link">
<ItemTemplate>
<%# Eval("QuoteLink") %>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtEditQuoteLink" runat="server" Text='<%# Bind("QuoteLink") %>'></asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Published">
<ItemTemplate>
<asp:CheckBox ID="chkBox" runat="server" Checked='<%# Convert.ToBoolean(Eval("Published")) %>' Enabled = "false" />
</ItemTemplate>
<EditItemTemplate>
<asp:CheckBox ID="chkEditBox" runat="server" Checked='<%# Bind("Published") %>' Enabled="true" />
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="PublishedDate">
<ItemTemplate>
<%# Convert.ToDateTime(DataBinder.Eval(Container.DataItem,"PublishedDate")).ToString("MM.dd.yyyy") %>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtEditPublishedDate" runat="server" Text='<%# Bind("PublishedDate") %>'></asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Commands">
<ItemTemplate>
<asp:ImageButton runat="server" ID="Edit" ImageUrl="/images/edit.gif" CommandName="Edit" />
<asp:ImageButton runat="server" ID="Delete" ImageUrl="/images/delete.gif" CommandName="Delete" />
</ItemTemplate>
<EditItemTemplate>
<asp:Button runat="server" ID="btn1" CommandName="Update" Text="Update" />
<asp:ImageButton runat="server" ID="Cancel" ImageUrl="/images/delete.gif" CommandName="Cancel" />
</EditItemTemplate>
</asp:TemplateField>
</Columns>
<EditRowStyle BackColor="#999999" />
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" HorizontalAlign="Left" ForeColor="White" />
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:SiteSqlServer %>"
DeleteCommand="DELETE FROM [Quotes] WHERE [Title] = #Title"
SelectCommand= "SELECT [Title], [Quote], [QuoteLink], [Published], [PublishedDate] FROM [Quotes]"
UpdateCommand="sp_UpdateQuotes" UpdateCommandType="StoredProcedure"
InsertCommand="INSERT INTO [Quotes] ([Title], [Quote], [QuoteLink], [Published], [PublishedDate]) VALUES (#Title, #Quote, #QuoteLink, #Published, #PublishedDate)">
<DeleteParameters>
<asp:Parameter Name="Title" Type="String" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="Title" Type="String" />
<asp:Parameter Name="Quote" Type="String" />
<asp:Parameter Name="QuoteLink" Type="String" />
<asp:Parameter Name="Published" Type="Boolean" />
<asp:Parameter Name="PublishedDate" Type="DateTime" />
</InsertParameters>
<UpdateParameters>
<asp:Parameter Name="Quote" Type="String" DefaultValue = "QUotes are simple" />
<asp:Parameter Name="QuoteLink" Type="String" DefaultValue = "QUotes are Linked" />
<asp:Parameter Name="Published" Type="Boolean" DefaultValue = "False" />
<asp:Parameter Name="PublishedDate" Type="DateTime" DefaultValue = "05/15/2011" />
</UpdateParameters>
</asp:SqlDataSource>
ALTER PROCEDURE [dbo].[sp_UpdateQuotes]
#Title varchar(max),
#Quote varchar(max),
#QuoteLink varchar(max),
#Published bit,
#PublishedDate DateTime
AS
BEGIN
UPDATE dbo.Quotes SET
Quote = #Quote,
QuoteLink = #QuoteLink,
Published = #Published,
PublishedDate = #PublishedDate
WHERE Title = #Title
If #Published = 1
BEGIN
UPDATE dbo.Quotes SET Published = 0 WHERE Title <> #Title AND Published = 1
END
END
Hope this would give you clear idea about what is messing me for update
You have not passed the #Title parameter, which is your primary Key in your stored procedure and is used in the where Clause.
If you want to see that there is no Title Parameter in Update Parameters:
<UpdateParameters>
<asp:Parameter Name="Quote" Type="String" />
<asp:Parameter Name="QuoteLink" Type="String" />
<asp:Parameter Name="Published" Type="Boolean" />
<asp:Parameter Name="PublishedDate" Type="DateTime" />
</UpdateParameters>
If you add the Title Parameter, it will work:
<asp:Parameter Name="Title" Type="String" />
I also had a problem with a GridView that was not updating. Inspection of the e.Newvalues Dictionary in the GridView's RowUpdating event showed that the old values for the record were being sent to the database UPDATE query. DataKeyNames was not my problem; I had it set correctly. The WHERE clause of my SELECT query referenced a control parameter against a TextBox on my form. I had inadvertently set EnableViewState for this textbox to "False". Because of this, the GridView was rebinding itself before the UPDATE occurred. Setting EnableViewState on the TextBox to "True" fixed the problem.
Protected Sub MyGridView_RowUpdating _
(sender As Object, e As System.Web.UI.WebControls.GridViewUpdateEventArgs) _
Handles MyGridView.RowUpdating
' Inspect the parameters being sent to the database for an ASP NET GridView UPDATE.
Dim I As Integer
I = 0
For Each MVO As System.Collections.DictionaryEntry In e.OldValues
If MVO.Value Is DBNull.Value OrElse MVO.Value Is Nothing Then
Debug.Print(I.ToString + ": " + MVO.Key + " Value: ")
Else
Debug.Print(I.ToString + ": " + MVO.Key + " Value: " + MVO.Value.ToString)
End If
I += 1
Next MVO
I = 0
For Each MVN As System.Collections.DictionaryEntry In e.NewValues
If MVN.Value Is DBNull.Value OrElse MVN.Value Is Nothing Then
Debug.Print(I.ToString + ": " + MVN.Key + " Value: ")
Else
Debug.Print(I.ToString + ": " + MVN.Key + " Value: " + MVN.Value.ToString)
End If
I += 1
Next MVN
End Sub

DetailsView update - not returning new values

After editing some fields, clicking on Update doesn't show the new values. I have tried two ways to retrieve the new values as you can see from this shortened version of the ItemUpdating event (and both return the old ones) :-
Protected Sub DetailsView1_ItemUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DetailsViewUpdateEventArgs) Handles DetailsView1.ItemUpdating
Dim txtPassword As TextBox = CType(DetailsView1.Rows(1).Cells(1).FindControl("txtPassword"), TextBox)
Struct_Student.password = txtPassword.Text
Dim PasswordValue As String = e.NewValues("password").ToString()
Struct_Student.password = PasswordValue
End Sub
Here is a shortened version of the aspx :-
<asp:Content ID="Content1" ContentPlaceHolderID="cpMainContent" Runat="Server">
<div id="Controls">
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:DetailsView ID="DetailsView1"
runat="server"
AutoGenerateRows="False"
DataKeyNames="student_id" DataSourceID="SqlDataSource1"
ForeColor="Blue"
BackColor="#FFF7E6"
AutoPostBack="True"
AutoGenerateEditButton = True
AutoGenerateInsertButton = True
OnModeChanging="StudentDetailView_ModeChanging"
Height=163px
Width=327px
style="left: 400px; top: 1px; position: absolute;">
<Fields>
<asp:TemplateField
HeaderText="Password">
<EditItemTemplate>
<asp:TextBox
id="txtPassword"
Text = '<%# Bind ("password") %>'
runat = "server" />
<asp:RequiredFieldValidator
ID = "reqPassword"
ControlToValidate = "txtPassword"
Text = "(required)"
Display = "Dynamic"
runat = "server" />
</EditItemTemplate>
<ItemTemplate>
<asp:Label
id="PasswordLabel"
runat="server"
Text = '<%# Eval("password") %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField
datafield="emailaddress"
headertext="Email address"
SortExpression="emailaddress"
/>
</Fields>
</asp:DetailsView>
<asp:SqlDataSource
ID="SqlDataSource1"
runat="server"
ConnectionString="<%$ ConnectionStrings:FCLManager %>" ProviderName="MySql.Data.MySqlClient"
SelectCommand="Select * from tblstudentinfo WHERE centre_id = #CentreID and fullname = #FullName"
<SelectParameters>
<asp:Parameter Name="CentreID" Type="Int16" DefaultValue="0" />
<asp:Parameter Name="FullName" Type="String" DefaultValue="0" />
</SelectParameters>
</asp:SqlDataSource>
</ContentTemplate>
</asp:UpdatePanel>
</div> <%--Controls div--%>
</asp:Content>

Resources