get_ReportControlSession NullReferenceException - c#

Server Error in '/' Application.
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[NullReferenceException: Object reference not set to an instance of an object.]
Microsoft.Reporting.WebForms.ReportViewer.get_ReportControlSession() +13
Microsoft.Reporting.WebForms.ReportViewerClientScript.SetViewerInfo(ReportViewer viewer, String reportAreaId, String promptAreaRowId, String docMapAreaId, String fixedTableId, String promptSplitterId, String docMapSplitterId, String docMapHeaderOverflowId, String directionCacheId, String browserModeCacheId) +1078
Microsoft.Reporting.WebForms.ReportViewer.OnPreRender(EventArgs e) +2696
System.Web.UI.Control.PreRenderRecursiveInternal() +90
System.Web.UI.Control.PreRenderRecursiveInternal() +163
System.Web.UI.Control.PreRenderRecursiveInternal() +163
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +906
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.8.4494.0
Base on information in stack trace above, non of it is from my own code.
Everything in code behind happen in Page_Load and there is try catch but it didn't catch any error. so I guess it's pointless for me to post the c# code.
This project is using visual studio 2015.
I am wondering where is the error come from.
<%# Page Language="C#" AutoEventWireup="true" CodeFile="GRNCostReportWeekly.aspx.cs" Inherits="Report_GRNCostReportWeekly" %>
<%# Register Assembly="Microsoft.ReportViewer.WebForms, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
Namespace="Microsoft.Reporting.WebForms" TagPrefix="rsweb" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>GRN Cost Report Weekly</title>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<div>
<rsweb:reportviewer id="ReportViewer1" runat="server" font-names="Verdana" font-size="8pt" height="400px" width="400px">
<LocalReport ReportPath="report\GRNCostReportWeekly.rdlc">
<DataSources>
<rsweb:ReportDataSource DataSourceId="ObjectDataSource1" Name="DataSet_fn_Get_GRN_Cost_Report_PNA" />
<rsweb:ReportDataSource DataSourceId="ObjectDataSource2" Name="DataSet_fn_Get_GRN_Cost_Report_NonPNA" />
<rsweb:ReportDataSource DataSourceId="ObjectDataSource3" Name="DataSet_fn_Get_GRN_Cost_Report_ALL" />
<rsweb:ReportDataSource DataSourceId="ObjectDataSource4" Name="DataSet_fn_Get_GRN_Cost_Report_Summary" />
</DataSources>
</LocalReport>
</rsweb:reportviewer>
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server" OldValuesParameterFormatString="original_{0}"
SelectMethod="GetData" TypeName="DataSetTableAdapters.fn_Get_GRN_Cost_Report_PNATableAdapter" ConvertNullToDBNull="True">
<SelectParameters>
<asp:ControlParameter ControlID="hdSite" DefaultValue="" Name="Site" PropertyName="Value" Type="String" />
<asp:ControlParameter ControlID="hdPeriod" Name="Period" PropertyName="Value" Type="Int32" />
<asp:ControlParameter ControlID="hdProdGroup" DefaultValue="" Name="ProdGroup" PropertyName="Value" Type="String" />
</SelectParameters>
</asp:ObjectDataSource>
<asp:ObjectDataSource ID="ObjectDataSource2" runat="server" OldValuesParameterFormatString="original_{0}"
SelectMethod="GetData" TypeName="DataSetTableAdapters.fn_Get_GRN_Cost_Report_NonPNATableAdapter" ConvertNullToDBNull="True">
<SelectParameters>
<asp:ControlParameter ControlID="hdSite" DefaultValue="" Name="Site" PropertyName="Value" Type="String" />
<asp:ControlParameter ControlID="hdPeriod" Name="Period" PropertyName="Value" Type="Int32" />
<asp:ControlParameter ControlID="hdProdGroup" DefaultValue="" Name="ProdGroup" PropertyName="Value" Type="String" />
</SelectParameters>
</asp:ObjectDataSource>
<asp:ObjectDataSource ID="ObjectDataSource3" runat="server" OldValuesParameterFormatString="original_{0}"
SelectMethod="GetData" TypeName="DataSetTableAdapters.fn_Get_GRN_Cost_Report_ALLTableAdapter" ConvertNullToDBNull="True">
<SelectParameters>
<asp:ControlParameter ControlID="hdSite" DefaultValue="" Name="Site" PropertyName="Value" Type="String" />
<asp:ControlParameter ControlID="hdPeriod" Name="Period" PropertyName="Value" Type="Int32" />
<asp:ControlParameter ControlID="hdProdGroup" DefaultValue="" Name="ProdGroup" PropertyName="Value" Type="String" />
</SelectParameters>
</asp:ObjectDataSource>
<asp:ObjectDataSource ID="ObjectDataSource4" runat="server" OldValuesParameterFormatString="original_{0}"
SelectMethod="GetData" TypeName="DataSetTableAdapters.fn_Get_GRN_Cost_Report_SummaryTableAdapter" ConvertNullToDBNull="True">
<SelectParameters>
<asp:ControlParameter ControlID="hdSite" DefaultValue="" Name="Site" PropertyName="Value" Type="String" />
<asp:ControlParameter ControlID="hdPeriod" Name="Period" PropertyName="Value" Type="Int32" />
<asp:ControlParameter ControlID="hdProdGroup" DefaultValue="" Name="ProdGroup" PropertyName="Value" Type="String" />
</SelectParameters>
</asp:ObjectDataSource>
<br />
<br />
<asp:HiddenField ID="hdSite" runat="server" Visible="False" />
<asp:HiddenField ID="hdPeriod" runat="server" Visible="False" />
<asp:HiddenField ID="hdProdGroup" runat="server" Visible="False" />
<br />
</div>
</form>
</body>
</html>
Below is code from web.config related to report:
<httpHandlers>
<add path="Reserved.ReportViewerWebControl.axd" verb="*" type="Microsoft.Reporting.WebForms.HttpHandler, Microsoft.ReportViewer.WebForms, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" validate="false"/>
</httpHandlers>
<compilation debug="true" targetFramework="4.0">
<assemblies>
<add assembly="Microsoft.ReportViewer.Common, Version=10.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
<add assembly="Microsoft.ReportViewer.WebForms, Version=10.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
</assemblies>
<buildProviders>
<add extension=".rdlc" type="Microsoft.Reporting.RdlBuildProvider, Microsoft.ReportViewer.WebForms, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
</buildProviders>
</compilation>
<system.webServer>
<validation validateIntegratedModeConfiguration="false"/>
<handlers>
<add name="ReportViewerWebControlHandler" preCondition="integratedMode" verb="*" path="Reserved.ReportViewerWebControl.axd" type="Microsoft.Reporting.WebForms.HttpHandler, Microsoft.ReportViewer.WebForms, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"/>
</handlers>
</system.webServer>

Related

DetailsView Error: "Must declare the scalar value..."

I am attempting to use DetailsView in ASP.NET and c# to show a list of students that are associated with the logged-in user (which will be a teacher after they login to the system). I have been trying to using scalar values so my program can be more dynamic once a teacher types in the last name of the student they want to find in the system. I'm not sure why I am getting the error
must declare the scalar value
when I (think I) am declaring it on the ASP side of my code. I've been searching for solutions to this for a couple of hours now so any and all help would be greatly appreciated.
ASP.NET Code:
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<asp:Table runat="server">
<asp:TableRow>
<asp:TableCell>
</asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell>
<asp:Label ID="lblUserBlank" runat="server" Text="joeB" ></asp:Label>
<asp:TextBox ID="txtSearch" runat="server"></asp:TextBox>
<asp:Button ID="btSearch" runat="server" OnClick="btSearch_Click" Text="Search" />
<asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False" DataKeyNames="LastName"
DataSourceID="SqlDataSource1" Height="50px" Width="125px">
<Fields>
<asp:BoundField DataField="StudentID" HeaderText="StudentID" ReadOnly="True" SortExpression="StudentID" />
<asp:BoundField DataField="LastName" HeaderText="LastName" SortExpression="LastName" />
<asp:BoundField DataField="FirstName" HeaderText="FirstName" SortExpression="FirstName" />
<asp:BoundField DataField="Age" HeaderText="Age" SortExpression="Age" />
<asp:BoundField DataField="TShirt_Size" HeaderText="TShirt_Size" SortExpression="TShirt_Size" />
</Fields>
<EmptyDataTemplate>
No Student found
</EmptyDataTemplate>
</asp:DetailsView>
<asp:SqlDataSource
runat="server"
ID="SqlDataSource1"
ConnectionString="<%$ ConnectionStrings:Lab3 %>"
SelectCommand="SELECT Student.StudentID, Student.LastName, Student.FirstName, Student.Age, Student.TShirt_Size FROM Student INNER JOIN Teacher ON Student.TeacherID = Teacher.TeacherID WHERE Teacher.Username = #Username AND Student.LastName = #LastName">
<SelectParameters>
<asp:ControlParameter ControlID="txtSearch" Name="#LastName" PropertyName="Text" Type="String" />
<asp:ControlParameter ControlID="lblUserBlank" Name="#Username" PropertyName="Text" Type="String" />
</SelectParameters>
</asp:SqlDataSource>
</asp:TableCell>
</asp:TableRow>
</asp:Table>
</asp:Content>
c# code behind:
protected void btSearch_Click(object sender, EventArgs e)
{
DetailsView1.DataBind();
}
Change this line:
<asp:ControlParameter ControlID="txtSearch" Name="#LastName" PropertyName="Text" Type="String" />
<asp:ControlParameter ControlID="lblUserBlank" Name="#Username" PropertyName="Text" Type="String" />
for this (remove the # char from the Name flag value):
<asp:ControlParameter ControlID="txtSearch" Name="LastName" PropertyName="Text" Type="String" />
<asp:ControlParameter ControlID="lblUserBlank" Name="Username" PropertyName="Text" Type="String" />

How to Search a GridView?

I have a textbox and search button. Currently the Search button doesn't do anything. I do not know how to search in a GridView. I have researched for a few hours and the examples do not work because I use Stored Procedures (one is a select statement that works for this GridView, meanwhile I see I would need some other select to get the search... but I don't see how to incorporate two selects here). How can I add a search to this?
<%# Page Title="" Language="C#" MasterPageFile="~/admin/admin.master" AutoEventWireup="true" CodeFile="viewregistrantpaper.aspx.cs" Inherits="viewreg" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<h1>View Registrant</h1>
<asp:TextBox ID="TxtSearch" runat="server" CssClass="formtextbox"></asp:TextBox>
<asp:Button ID="BtnSearch" runat="server" onclick="BtnSearch_Click" Text="Search" CssClass="formbutton" />
<asp:GridView ID="GridView1" runat="server" AllowPaging="True"
AllowSorting="True" AutoGenerateColumns="False"
DataSourceID="SqlDataSourceViewRegistrant"
CssClass="mGrid"
PagerStyle-CssClass="pgr"
AlternatingRowStyle-CssClass="alt" >
<AlternatingRowStyle CssClass="alt"></AlternatingRowStyle>
<Columns>
<asp:CommandField ShowDeleteButton="True" ShowEditButton="True" />
<asp:BoundField DataField="LocalNumberId" HeaderText="Local"
SortExpression="LocalNumberId" />
<asp:BoundField DataField="LocalUnionEmail" HeaderText="Local Email"
SortExpression="LocalUnionEmail" />
<asp:BoundField DataField="DistrictId" HeaderText="District"
SortExpression="DistrictId" />
<asp:BoundField DataField="CompletedByFirstName" HeaderText="Completed By First Name"
SortExpression="CompletedByFirstName" />
<asp:BoundField DataField="CompletedByLastName" HeaderText="Completed By Last Name"
SortExpression="CompletedByLastName" />
<asp:BoundField DataField="CompletedByPhone" HeaderText="Completed By Phone"
SortExpression="CompletedByPhone" />
<asp:BoundField DataField="FirstName" HeaderText="First Name"
SortExpression="FirstName" />
<asp:BoundField DataField="LastName" HeaderText="Last Name"
SortExpression="LastName" />
<asp:BoundField DataField="Position" HeaderText="Position"
SortExpression="Position" />
<asp:BoundField DataField="Email" HeaderText="Email"
SortExpression="Email" />
<asp:BoundField DataField="ShirtSize" HeaderText="Shirt Size"
SortExpression="ShirtSize" />
<asp:BoundField DataField="Comments" HeaderText="Comments"
SortExpression="Comments" />
</Columns>
<PagerStyle CssClass="pgr"></PagerStyle>
</asp:GridView>
<div style=" width:100%; overflow: hidden;">
<asp:SqlDataSource ID="SqlDataSourceViewRegistrant" runat="server"
ConnectionString="<%$ ConnectionStrings:Events2 %>"
DeleteCommand="spDelRegistrant" DeleteCommandType="StoredProcedure"
InsertCommand="spInsRegistrantPaper" InsertCommandType="StoredProcedure"
SelectCommand="spGetRegistrantPaper" SelectCommandType="StoredProcedure"
UpdateCommand="spUpdateRegistrantPaper"
UpdateCommandType="StoredProcedure">
<DeleteParameters>
<asp:Parameter Name="RegistrantId" Type="Int32" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="EventId" Type="Int32" />
<asp:Parameter Name="LocalNumber" Type="Int32" />
<asp:Parameter Name="LocalUnionEmail" Type="String" />
<asp:Parameter Name="DistrictId" Type="Int32" />
<asp:Parameter Name="CompletedByFirstName" Type="String" />
<asp:Parameter Name="CompletedByLastName" Type="String" />
<asp:Parameter Name="CompletedByPhone" Type="String" />
<asp:Parameter Name="FirstName" Type="String" />
<asp:Parameter Name="LastName" Type="String" />
<asp:Parameter Name="Position" Type="String" />
<asp:Parameter Name="Email" Type="String" />
<asp:Parameter Name="ShirtSize" Type="String" />
<asp:Parameter Name="Comments" Type="String" />
</InsertParameters>
<UpdateParameters>
<asp:Parameter Name="RegistrantId" Type="Int32" />
<asp:Parameter Name="LocalNumber" Type="Int32" />
<asp:Parameter Name="LocalUnionEmail" Type="String" />
<asp:Parameter Name="DistrictId" Type="Int32" />
<asp:Parameter Name="CompletedByFirstName" Type="String" />
<asp:Parameter Name="CompletedByLastName" Type="String" />
<asp:Parameter Name="CompletedByPhone" Type="String" />
<asp:Parameter Name="FirstName" Type="String" />
<asp:Parameter Name="LastName" Type="String" />
<asp:Parameter Name="Position" Type="String" />
<asp:Parameter Name="Email" Type="String" />
<asp:Parameter Name="ShirtSize" Type="String" />
<asp:Parameter Name="Comments" Type="String" />
</UpdateParameters>
</asp:SqlDataSource>
</div>
</p>
</asp:Content>
UPDATE:
<SelectParameters>
<asp:ControlParameter ControlID="TxtSearch" Name="FirstName" PropertyName="Text" Type="String" DefaultValue="%%" />
<asp:Parameter Name="FirstName" Type="String" />
</SelectParameters>
Stored Procedure:
USE [Events2]
GO
/****** Object: StoredProcedure [dbo].[spGetRegistrantPaper] Script Date: 11/25/2015 11:10:14 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[spGetRegistrantPaper]
-- Add the parameters for the stored procedure here
#FirstName nVarChar (255)
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
SELECT LocalNumberId,
LocalUnionEmail,
DistrictId,
CompletedByFirstName,
CompletedByLastName,
CompletedByPhone,
FirstName,
LastName,
Position,
Email,
ShirtSize,
Comments
FROM Registrant
WHERE FirstName LIKE '%' + #FirstName + '%'
END
You will have have to modify your Stored Procedure spGetRegistrantPaper to send filtered records to the web application. You can modify it with a Where clause like this (for eg):-
SELECT * FROM RegistrantPaper WHERE FirstName LIKE '%' + #Name + '%'
Where, #Name will be input parameter in your SP.
Next, add a Select Parameter to your SQLDataSource mark-up like this:-
<SelectParameters>
<asp:ControlParameter ControlID="TxtSearch" Name="Name" PropertyName="Text"
Type="String" DefaultValue="%%" />
</SelectParameters>

Gridview with Sqldatasource Edit/Delete buttons

I'm using asp.net with c# code behind, and all I want to do is have a gridview+sqldatasource that I can manipulate at runtime and for whatever reason the buttons don't work. I have a login page that passes the username over via querystring and then this page is ONLY a gridview right now. When I click the delete button it immediately takes me to the login page with the fields blank again. For testing purposes I'm using just the delete button but I've had the same experience with the edit button as well, it never does the "update mode" like it seems it should.
<asp:GridView DataKeyNames="ID" ID="GridView1" runat="server" DataSourceID="SqlDataSource1" AllowPaging="True" AllowSorting="True" PageSize="8" OnRowDataBound="GridView1_RowDataBound">
<Columns>
<asp:CommandField ShowDeleteButton="True" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString='<%$ ConnectionStrings:WebMasterLogConnectionString2 %>'
SelectCommand="SELECT * FROM [WebmasterLogs] WHERE ([Username] = #Username) ORDER BY [ID]"
ConflictDetection="CompareAllValues"
DeleteCommand="DELETE FROM [WebmasterLogs] WHERE [ID] = #original_ID"
OldValuesParameterFormatString="original_{0}" >
<DeleteParameters>
<asp:Parameter Name="original_ID" Type="Int32" />
</DeleteParameters>
<SelectParameters>
<asp:Parameter Name="ID" Type="Int32" />
<asp:QueryStringParameter Name="Username" QueryStringField="Username" Type="String" />
<asp:Parameter Name="LogEntryDate" Type="DateTime" />
<asp:Parameter Name="TimeSpent" Type="String" />
<asp:Parameter Name="Description" Type="String" />
</SelectParameters>
</asp:SqlDataSource>
Web Config:
<configuration>
<configSections>
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<system.web>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5" />
</system.web>
<appSettings>
<add key="ValidationSettings:UnobtrusiveValidationMode" value="None" />
</appSettings>
<connectionStrings>
<add name="WebMasterLogConnectionString" connectionString="Data Source=35sql;Initial Catalog=WebMasterLog;Persist Security Info=False;User ID=*****;Password=*********"
providerName="System.Data.SqlClient" />
</connectionStrings>
</configuration>
There is NO need to define the Delete parameter here since the #original_ID parameter will be automatically submitted by the data control because of the setting OldValuesParameterFormatString="original_{0}".
Therefore the parameter #original_ID will have the appropriate ID value already.
The <asp:Parameter ... /> declaration is used only when you want to set the parameter programmatically.
Figured this out. I hadn't defined the click events properly for editing/updating/deleting.

Cannot call update function on gridview

I have aproblem everytime I call my update function,
I belive that the source of the problem is because this function gets object paramter,
and also get a paramter from diffrant souce, and i am not doing it currectly.
This is the error:
http://prntscr.com/2z0cd6
GridView code:
<asp:GridView ID="gvAnimals" runat="server" AutoGenerateColumns="False" CellPadding="4" DataSourceID="ObjectDataSourceAnimals" ForeColor="#333333" GridLines="None" DataKeyNames="animalId">
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
<Columns>
<asp:CommandField ShowDeleteButton="True" ShowEditButton="True" />
<asp:BoundField DataField="animalId" HeaderText="animalId" SortExpression="animalId" />
<asp:BoundField DataField="name" HeaderText="name" SortExpression="name" />
<asp:CheckBoxField DataField="vertebrates" HeaderText="vertebrates" SortExpression="vertebrates" />
<asp:CheckBoxField DataField="vegetarian" HeaderText="vegetarian" SortExpression="vegetarian" />
<asp:CheckBoxField DataField="terrestrial" HeaderText="terrestrial" SortExpression="terrestrial" />
<asp:BoundField DataField="kind" HeaderText="kind" SortExpression="kind" />
<asp:BoundField DataField="avgWeight" HeaderText="avgWeight" SortExpression="avgWeight" />
<asp:BoundField DataField="avgHeight" HeaderText="avgHeight" SortExpression="avgHeight" />
<asp:BoundField DataField="infoAdress" HeaderText="infoAdress" SortExpression="infoAdress" />
<asp:BoundField DataField="imageAdress" HeaderText="imageAdress" SortExpression="imageAdress" />
</Columns>
<EditRowStyle BackColor="#999999" />
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#E9E7E2" />
<SortedAscendingHeaderStyle BackColor="#506C8C" />
<SortedDescendingCellStyle BackColor="#FFFDF8" />
<SortedDescendingHeaderStyle BackColor="#6F8DAE" />
</asp:GridView>
<asp:ObjectDataSource ID="ObjectDataSourceAnimals" runat="server" DeleteMethod="DeleteAnimal" OldValuesParameterFormatString="original_{0}" SelectMethod="GetAllAnimals" TypeName="BLProject.Animal" UpdateMethod="UpdateAnimal" DataObjectTypeName="BLProject.Animal">
<DeleteParameters>
<asp:Parameter Name="a" Type="Object" />
<asp:SessionParameter Name="newsAdress" SessionField="Adress" Type="String" />
</DeleteParameters>
<SelectParameters>
<asp:ControlParameter ControlID="textSearch" Name="Search" PropertyName="Text" Type="String" />
<asp:ControlParameter ControlID="dropdownlistAnimalToSearch" Name="type" PropertyName="SelectedValue" Type="String" />
</SelectParameters>
<UpdateParameters>
<asp:Parameter Name="a" Type="Object" />
<asp:SessionParameter DefaultValue="D:\\project\\Ilan Project 29-11\\Web\\NewsInfo" Name="newsAdress" SessionField="Adress" Type="String" />
</UpdateParameters>
</asp:ObjectDataSource>
*I belive that the source of the error is in the bold lines
The Update function:
[DataObjectMethod(DataObjectMethodType.Update)]
public static int UpdateAnimal(Animal a, string newsAdress)
Animal a is the object paramter which the grid view get by using the select function,
but the adress is another paramter from session source which the function gets too.
However, since I added this paramter I have this new error.
Thanks.
You can do it like this:
Change your method with this one
public void UpdateAnimal(int animalId, string name, bool vertebrates, bool vegetarian, string newsAdress)
{
}
and your ObjectDataSource
<asp:ObjectDataSource ID="ObjectDataSourceAnimals" runat="server" DeleteMethod="DeleteAnimal" SelectMethod="GetAllAnimals" TypeName="BLProject.Animal" UpdateMethod="UpdateAnimal">
<DeleteParameters>
<asp:Parameter Name="a" Type="Object" />
<asp:SessionParameter Name="newsAdress" SessionField="Adress" Type="String" />
</DeleteParameters>
<SelectParameters>
<asp:ControlParameter ControlID="textSearch" Name="Search" PropertyName="Text" Type="String" />
<asp:ControlParameter ControlID="dropdownlistAnimalToSearch" Name="type" PropertyName="SelectedValue" Type="String" />
</SelectParameters>
<UpdateParameters>
<asp:Parameter Name="animalId" Type="Int32"/>
.......the other fields from Animal that you want to update
<asp:Parameter Name="name" Type="String"/>
<asp:Parameter Name="vegetarian" Type="Boolean"/>
<asp:Parameter Name="vertebrates" Type="Boolean"/>
<asp:SessionParameter DefaultValue="D:\\project\\Ilan Project 29-11\\Web\\NewsInfo" Name="newsAdress" SessionField="Adress" Type="String" />
</UpdateParameters>
</asp:ObjectDataSource>
Seems that when using DataObjectTypeName you cannot add parameters. The solution is to send some or all the properties of the Animal row edited as parameters plus the other parameter.
If you want to use OldValuesParameterFormatString="original_{0}", add this int original_animalid to the method input parameters.

Can't change Formview mode on GridView_SelectedIndexChanged

I want my Formview to start in Insert mode and then change to Edit mode when a user selects a row from the Gridview in the same page.
The Formview has the inline attribute: DefaultMode="Insert"
How can this be done and why isn't this working?
protected void GridView1_SelectedIndexChanged(object sender, System.EventArgs e)
{
FormView1.ChangeMode(FormViewMode.Edit);
}
Edit1:
FormView Source code
<asp:FormView ID="FormView1" runat="server" DataKeyNames="AdID" DataSourceID="AdByID" DefaultMode="Insert">
<EditItemTemplate>
Caption:
<asp:TextBox ID="CaptionTextBox" runat="server" Text='<%# Bind("Caption") %>' />
<br />
Summary:
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("Summary") %>'></asp:TextBox>
<br />
Text:
<telerik:RadEditor ID="RadEditor1" Runat="server" Content='<%# Bind("Text") %>' ToolsFile="~/crm/annonser/ToolsFile.xml"
Language="sv-SE" ToolbarMode="Default"
AllowScripts="True" EditModes="Design" Skin="Office2007"
StripFormattingOnPaste="MSWord" Width="500px">
<Content>
</Content>
</telerik:RadEditor>
<br />
Name:
<asp:TextBox ID="NameTextBox" runat="server" Text='<%# Bind("Name") %>' />
<br />
Email:
<asp:TextBox ID="EmailTextBox" runat="server" Text='<%# Bind("Email") %>' />
<br />
Phone:
<asp:TextBox ID="PhoneTextBox" runat="server" Text='<%# Bind("Phone") %>' />
<br />
PhoneHidden:
<asp:CheckBox ID="PhoneHiddenCheckBox" runat="server"
Checked='<%# Bind("PhoneHidden") %>' />
<br />
Price:
<asp:TextBox ID="PriceTextBox" runat="server" Text='<%# Bind("Price") %>' />
<br />
CategoryCodeID:
<asp:DropDownList ID="DropDownList2" runat="server"
DataSourceID="AdCategoryMarket" DataTextField="Caption"
DataValueField="AdCategoryCodeID" SelectedValue='<%# Bind("CategoryCodeID") %>'>
</asp:DropDownList>
<asp:ObjectDataSource ID="AdCategoryMarket" runat="server"
DeleteMethod="Delete" InsertMethod="Insert"
OldValuesParameterFormatString="original_{0}" SelectMethod="GetData"
TypeName="dsCRMTableAdapters.app_AdCategoryCodeTableAdapter"
UpdateMethod="Update">
<DeleteParameters>
<asp:Parameter Name="Original_AdCategoryCodeID" Type="Int32" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="Caption" Type="String" />
<asp:Parameter Name="DisplayOrder" Type="Int32" />
<asp:Parameter Name="CategoryTypeID" Type="Int32" />
</InsertParameters>
<UpdateParameters>
<asp:Parameter Name="Caption" Type="String" />
<asp:Parameter Name="DisplayOrder" Type="Int32" />
<asp:Parameter Name="CategoryTypeID" Type="Int32" />
<asp:Parameter Name="Original_AdCategoryCodeID" Type="Int32" />
</UpdateParameters>
</asp:ObjectDataSource>
<br />
StateCodeID:
<asp:DropDownList ID="DropDownList3" runat="server" DataSourceID="AdStateCode"
DataTextField="Caption" DataValueField="AdStateCodeID"
SelectedValue='<%# Bind("StateCodeID") %>'>
</asp:DropDownList>
<asp:ObjectDataSource ID="AdStateCode" runat="server" DeleteMethod="Delete"
InsertMethod="Insert" OldValuesParameterFormatString="original_{0}"
SelectMethod="GetData"
TypeName="dsCRMTableAdapters.app_AdStateCodeTableAdapter" UpdateMethod="Update">
<DeleteParameters>
<asp:Parameter Name="Original_AdStateCodeID" Type="Byte" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="Caption" Type="String" />
</InsertParameters>
<UpdateParameters>
<asp:Parameter Name="Caption" Type="String" />
<asp:Parameter Name="Original_AdStateCodeID" Type="Byte" />
</UpdateParameters>
</asp:ObjectDataSource>
<br />
RegionCodeID:
<asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="Regions"
DataTextField="name" DataValueField="RegionCodeID"
SelectedValue='<%# Bind("RegionCodeID") %>'>
</asp:DropDownList>
<asp:ObjectDataSource ID="Regions" runat="server"
OldValuesParameterFormatString="original_{0}" SelectMethod="GetData"
TypeName="dsCRMTableAdapters.app_RegionCodeTableAdapter">
</asp:ObjectDataSource>
<br />
StopDate:
<telerik:RadDatePicker ID="RadDatePicker1" Runat="server" Culture="sv-SE"
DbSelectedDate='<%# Bind("StopDate") %>'>
</telerik:RadDatePicker>
<br />
<br />
<asp:LinkButton ID="InsertButton" runat="server" CommandName="Insert" Text="Insert" />
<asp:LinkButton ID="UpdateButton" runat="server" CommandName="Update" Text="Update" CommandArgument='<%# Eval("AdID") %>' />
<asp:LinkButton ID="UpdateCancelButton" runat="server" CausesValidation="False" CommandName="Cancel" Text="Cancel" />
</EditItemTemplate></asp:FormView>
FormView DataSource
<asp:ObjectDataSource ID="AdByID" runat="server"
OldValuesParameterFormatString="original_{0}" SelectMethod="GetDataByID"
TypeName="dsCRMTableAdapters.app_AdTableAdapter" DeleteMethod="Delete"
InsertMethod="Insert" UpdateMethod="Update">
<DeleteParameters>
<asp:Parameter Name="Original_AdID" Type="Int32" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="Caption" Type="String" />
<asp:Parameter Name="Summary" Type="String" />
<asp:Parameter Name="Text" Type="String" />
<asp:Parameter Name="Name" Type="String" />
<asp:Parameter Name="Email" Type="String" />
<asp:Parameter Name="Phone" Type="String" />
<asp:Parameter Name="PhoneHidden" Type="Boolean" />
<asp:Parameter Name="Price" Type="Decimal" />
<asp:Parameter Name="CategoryCodeID" Type="Byte" />
<asp:Parameter Name="StateCodeID" Type="Byte" />
<asp:Parameter Name="RegionCodeID" Type="Byte" />
<asp:Parameter Name="StopDate" Type="DateTime" />
<asp:Parameter Name="ModifiedBy" Type="Int32" />
<asp:Parameter Name="CreatedOn" Type="DateTime" />
<asp:Parameter Name="ModifiedOn" Type="DateTime" />
<asp:Parameter DbType="Guid" Name="AdGUID" />
</InsertParameters>
<SelectParameters>
<asp:ControlParameter ControlID="GridView1" Name="AdID" PropertyName="SelectedValue" Type="Int32" DefaultValue="0" />
</SelectParameters>
<UpdateParameters>
<asp:Parameter Name="Caption" Type="String" />
<asp:Parameter Name="Summary" Type="String" />
<asp:Parameter Name="Text" Type="String" />
<asp:Parameter Name="Name" Type="String" />
<asp:Parameter Name="Email" Type="String" />
<asp:Parameter Name="Phone" Type="String" />
<asp:Parameter Name="PhoneHidden" Type="Boolean" />
<asp:Parameter Name="Price" Type="Decimal" />
<asp:Parameter Name="CategoryCodeID" Type="Byte" />
<asp:Parameter Name="StateCodeID" Type="Byte" />
<asp:Parameter Name="RegionCodeID" Type="Byte" />
<asp:Parameter Name="StopDate" Type="DateTime" />
<asp:Parameter Name="ModifiedBy" Type="Int32" />
<asp:Parameter Name="CreatedOn" Type="DateTime" />
<asp:Parameter Name="ModifiedOn" Type="DateTime" />
<asp:Parameter DbType="Guid" Name="AdGUID" />
<asp:Parameter Name="Original_AdID" Type="Int32" />
</UpdateParameters></asp:ObjectDataSource>
The data is updated as expected but no events seems to fire... the following redirect simply doesn't happen:
protected void FormView1_ItemUpdated(Object sender, FormViewCommandEventArgs e)
{
Response.Redirect("www.stackoverflow.com");
}
The initial problem most likely resides from there, don't you think? The question is, how do I get the events to work as expected?

Categories

Resources