IEnumerable Not Null But Calling Count() Results In Exception?
Jun 2, 2010
I have code that's working beautifully on my development machine,but when deployed to the server is throwing null reference exception.So,I can't step through the code,but I've pinned down the culprit.But now I am puzzled.Here's the code.The question is below.
Dim certs = From p In persons _
Select New Certificate( _
p.Value, _
New CertificateData.Seminar(thisEvent.Seminar.Name, _
[code]...
In the code above persons is a dictionary of custom class,and certs is of IEnumerable type.Now here's the quandary.The first line that sets the label returns False,so certs is not null.But the second line throws an null reference exception.
View 1 Replies
Similar Messages:
Apr 8, 2010
This is probably something silly I'm missing but I'm definitely lost. I'm using .NET 4 RC and VS 2010. This is also my first attempt to use UpdateModel in .NET 4, but every time I call it, I get an exception saying Value cannont be null or empty. I've got a simple ViewModel called LogOnModel:
[Code]....
My view uses the new strongly typed helpers in MVC2 to generate a textbox for username and one for the password. When I look at FormCollection in my controller method, I see values for both coming through.
And last but not least, here's are post controller methods:
[Code]....
why UpdateModel would be throwing this exception?
View 4 Replies
Mar 14, 2010
I have a dataset that has two datatables. In the first datatable I have EmpNo,EmpName and EmpAddress. In the second datatable I have Empno,EmpJoindate, EmpSalary. I want a result where I should show EmpName as the label and his/her details in the gridview. I populate a datalist with the first table, and have EmpNo as the datakeys. Then I populate the gridview inside the datatable which has EmpNo,EmpJoinDate and EmpAddress. My code is
[Code]....
My Design is
<asp:DataList ID="Datalist1" runat="server" DataKeyField="EmpNo">
<ItemTemplate>
<asp:GridView ID="Gridview1" runat="server">
</asp:GridView>
</ItemTemplate>
</asp:DataList>
I do not get results in the gridview, instead have errors. I tried then placing the bound field
<asp:GridView ID="Gridview1" AutoGenerateColumns="true" runat="server">
<Columns>
<asp:BoundField DataField="EmpNo" />
</Columns>
It throwed an error stating / A field or property with the name 'EmpNo' was not found on the selected data source.
View 3 Replies
Feb 14, 2011
I have a IEnumerable result, passed to my view. Now, I want to display five elements for my Model in one row and next five in second row. How can I do that?
View 1 Replies
Feb 3, 2010
i'm using MVC 2, RC, and i have a controller method:
[Code]....
and i have an <input type="file"../> in my form. during post, however, the files parameter is null.
View 9 Replies
Aug 17, 2010
I have simple 3 tier web application and have mostly CRUDE functionalities. Recently I required to add new console application to the existing solution in which I call data layer methods for retrieving data from DB but I get an exception "The type initializer for threw an exception."When I debugged I found that the exception is thrown at datalayer on first line of class where I get connectionstring from
web.config, the code is public static readonly string CONNECT_STRING =
ConfigurationManager.ConnectionStrings["DbConnectString"].ConnectionString;
Now if I hardcode the connection string value like public static readonly string CONNECT_STRING = "Data Source=XYZ;uid=sa;password=XXX;initial catalog=ABC;"
it works fine.I don't understand what is the issue here as web application works fine with this datalayer.
View 2 Replies
Mar 10, 2011
I have a model called 'BusinessPage' which can be associated with 1 or more 'BusinessPageCategories'. So I've got a 3rd table called 'BusinessPagesInCategories' that links these two.I am trying to get a paged recordset of BusinessPages, along with the total number of records (I may have 100 rows in total but only return 20 at a time, but I pass back an int containing that total number in addition to the 20 rows).The problem I have is that, since I implemented the Many-To-Many relationship, it was bringing back the same BusinessPage row x times (where x is the number of categories that BusinessPage is associated with). I only want a single instance of each business page to be returned. So I added the following to my NHibernate Criteria to give Distinct BusinessPage results..SetResultTransformer(CriteriaSpecification.DistinctRootEntity);
Whilst this works for me, in that I'm now correctly getting a single row per BusinessPage (and my Categories property within each BusinessPage contains the correct x categories that it's assigned to), my row count is not reflecting that 'distinct' count - instead, if I have just 1 BusinessPage record which is associated with 3 categories, the row count is 3!?!
public virtual int BusinessPageId { get; private set; }
public virtual IList<BusinessPageCategory> Categories { get; set; }
public virtual string BusinessName { get; set; }
[code]...
View 1 Replies
Apr 9, 2010
I want to count the number of results results returned by my query and print the number to a literal on the page.How would I do that?
View 2 Replies
Dec 13, 2010
I am trying to show the results of a function with information from a form on the previous page.I was working on this project in the past and the following code worked, but it does not anymore.I know its alot to look at but if someone could help that would be great.The form on the first asp page:
<FORM METHOD="POST" ACTION="RollingRiverFarmCustomerQuote.asp" id="InformationForm">
View 10 Replies
Apr 1, 2010
Can i customize gridview to show Reuslt summary in the footer or pager like
[Results: 1- 10 of 2000]
View 4 Replies
Apr 18, 2013
The query I used here is
SELECT top '"+lblCount.text+"' Company_Id, CompanyName, All_Countries,All_Industries,Employees,Revenue, Status FROM SN001CompanyTable where Client_Id=100 ORDER BY [Company_Id] DESC
but its not showing proper results..
In this lblCount contains the no of row to be displayed..
View 1 Replies
Jan 17, 2011
I am using AjaxToolkit 4.0 which suggests to use ToolkitScriptManager in place of ScriptManager. But when I am using ToolkitScriptManager, it throws javascript exception when Page_ClientValidate() in called from javascript. However, this error is not coming when ScriptManager is used. Can anybody tell me how to make Page_ClientValidate() run when using ToolkitScriptManager?
View 1 Replies
Mar 17, 2010
From my windows mobile application, i want to connect to the server which resides on my local machine. I want to use HTTPS.
SSL certificates have been implemented and they dont cause any problems.
However, i get an exception at the code line
Stream requestStream = webrequest.GetRequestStream(); ----> webrequest is an object of HttpWebRequest class
The exception message is "Could not establish connection to network." InnerException is null.
View 2 Replies
May 11, 2010
I need to concatenate several columns of a table into a single value, then show that value in an asp dropdownlist. The SQL code I'm issuing is as follows:
SELECT UserID, CustomerNum, UserName + ' - ' + UserAddress + ',' + UserCity + ' ' + UserState AS UserInfo
FROM Users
WHERE (CustomerNum = @CustomerNum)
ORDER BY UserName
I then set 'UserInfo' as the text field in the dropdownlist.This generally works, except occasionally one of the columns in the database is null (for example, UserState). When that happens, the entire concatenation is null, and I get an empty entry in the dropdownlist.
Is there something in SQLServer that will allow me to ignore those NULL results, or will I have to code something up in the DataBind event?
View 6 Replies
Jul 1, 2010
I'm trying to implement a view tracking web service on my website. I'm using JavaScript because I want to exclude any search bots from my tracked views. The problem is I'm getting a "Unknown web method" error when I try to use jQuery to post to the web service I've created.
$(document).ready(function() {
$.ajax({
type: "POST", [code]...
The error is an ASP .NET error: Unknown web method TrackItemView. Parameter name: methodName.I've done this hundreds of times (seemingly), but I just can't see what I'm missing. I'm sure it's something small...
View 1 Replies
Feb 27, 2011
i want my query to return results where the field address is not empty or null
however, the query i have is still returning results where address is empty i.e. ' ' .
View 2 Replies
Jul 23, 2010
The way this page is laid out, all of the data is loaded at Page_Init. Well, I have a custom control that is having problems with this though.
I have it on the page like so:
<cc:SomeControl... />
And then I set the value at Page_Init using
MyControl.Value="blah";
Simple stuff..
The Value is an accessor and has something similar to this:
public string Value{
get...
set{
EnsureChildControls();
MyHiddenField.Value=value;
}
}
and it is here that I have a problem. It says that MyHiddenField is null. Is Page_Init just too early for this? Or is there some other function I need to call?
View 1 Replies
Sep 1, 2010
I'm getting a null reference exception whenever I try to databind this datatable to the Gridview. I know for sure that the datatable has data. I've checked it.
[Code]....
I get the error when it gets to the last line here..
View 8 Replies
Jul 22, 2010
I wanted to get the total row count in a GridView's databound event handler, so I tried the following:
protected void grid_DataBound(object sender, EventArgs e)
{
GridView grid = (GridView)sender;
DataSet data = grid.DataSource as DataSet;
if (data == null)
return;
int totalRows = data.Tables[0].Rows.Count;
}
The problem is that the grid.DataSource property is null. The DataSourceID property is not null, so does that mean that I can't access the DataSource object in the DataBound event handler unless I assign the DataSource property directly?
Edit1: Here is the code in my GridHelper class for adding rowcount to the BottomPagerRow. I would like to get rid of the requirement to pass in the ObjectDataSource, but can't because I need to use the Selected event to get total row count. Hence the reason for the question. I also think this might be better in a custom control where I can access ViewState, and/or create child controls during the Init event (I still have a problem to resolve with the way the pager renders with an extra cell), but then I'd still have the problem of how to get to the total row count when the DataSource itself doesn't appear to be available in any GridView events.
Edit 2: Not really relevant to the specific problem, but I resolved the problem I was having with the pager rendering so i've updated the code posted. I found the trick here: [URL]
#region Fields
private int totalRows = -1;
#endregion
#region Constructors
/// <summary>
/// Initializes a new instance of the <see cref="GridHelper"/> class.
/// Adds EventHandlers to the GridView to display results from the ObjectDataSource in the footer.
/// Marked as obsolete because AddResultsToFooter method provides a static access to the same functionality
/// An instance of GridHelper is required by the passed in GridView to store the totalRows value between the two event handlers
/// </summary>
/// <param name="grid">The grid.</param>
/// <param name="source">The ObjectDataSource linked to the GridView.</param>
[Obsolete("Use AddResultsToFooter instead.")]
[EditorBrowsable(EditorBrowsableState.Never)]
public GridHelper(GridView grid, ObjectDataSource source)
{
source.Selected += source_Selected;
grid.PreRender += grid_PreRender;
}
#endregion
#region Event Handlers
private void grid_PreRender(object sender, EventArgs e)
{
GridView grid = (GridView)sender;
if (grid.HeaderRow != null)
grid.HeaderRow.TableSection = TableRowSection.TableHeader;
//Add a cell to the bottom pager row to display the total results
if (grid.BottomPagerRow == null || !grid.BottomPagerRow.Visible)
return;
//Get the control used to render the pager
//http://michaelmerrell.com/2010/01/dynamically-modifying-the-asp-net-gridview-paging-control/
Table tblPager = grid.BottomPagerRow.Cells[0].Controls[0] as Table;
if (tblPager == null)
return;
if (totalRows < 0)
{
//The DataSource has not been refreshed so get totalRows from round trip to client
addResultsToPagerTable(tblPager, grid.Attributes["results"]);
return;
}
int firstRow = grid.PageIndex * grid.PageSize + 1;
int lastRow = firstRow + grid.Rows.Count - 1;
string results;
if (totalRows <= grid.PageSize)
results = string.Format("<span class='grid-pager'>{0} Results</span>", totalRows);
else
results = string.Format("Results <b>{0}</b> to <b>{1}</b> of <b>{2}</b>", firstRow, lastRow, totalRows);
addResultsToPagerTable(tblPager, results);
//Need to store the information somewhere that is persisted via ViewState, and we don't have access to ViewState here
grid.Attributes.Add("results", results);
}
/// <summary>
/// Handles the Selected event of the source control. Gets the total rows, since it is not possible to access them from the GridView.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="System.Web.UI.WebControls.ObjectDataSourceStatusEventArgs"/> instance containing the event data.</param>
private void source_Selected(object sender, ObjectDataSourceStatusEventArgs e)
{
if (e.ReturnValue is DataView)
totalRows = ((DataView)e.ReturnValue).Count;
else if (e.ReturnValue is EntitySet)
totalRows = ((EntitySet)e.ReturnValue).Count;
}
#endregion
#region Private Methods
private static void addResultsToPagerTable(Table tblPager, string results)
{
//http://michaelmerrell.com/2010/01/dynamically-modifying-the-asp-net-gridview-paging-control/
//Get a handle to the original pager row
TableRow pagesTableRow = tblPager.Rows[0];
//Add enough cells to make the pager row bigger than the label we're adding
while (pagesTableRow.Cells.Count < 10)
pagesTableRow.Cells.Add(new TableCell { BorderStyle = BorderStyle.None });
//Add a new cell in a new row to the table
TableRow newTableRow = new TableRow();
newTableRow.Cells.AddAt(0, new TableCell
{
Text = results,
BorderStyle = BorderStyle.None,
ColumnSpan = pagesTableRow.Cells.Count
});
tblPager.Rows.AddAt(0, newTableRow);
}
#endregion
#region Public Methods
/// <summary>
/// Adds EventHandlers to the GridView to display results from the ObjectDataSource in the footer.
/// </summary>
/// <param name="grid">The GridView.</param>
/// <param name="source">The ObjectDataSource linked to the GridView.</param>
public static void AddResultsToFooter(GridView grid, ObjectDataSource source)
{
if (grid == null)
throw new ArgumentNullException("grid", "grid is null.");
if (source == null)
throw new ArgumentNullException("source", "source is null.");
new GridHelper(grid, source);
}
#endregion
View 1 Replies
Sep 23, 2010
Im trying to resize an image. I have the original file and then try to resize it and save it to a new image.However, I get an exception because the value of stream cannot be null. This makes sense, but I dont know how to prevent it:
Value cannot be null.
Parameter name: stream
Description: An unhandled exception occurred during the execution of the current web request.
Source Error:
[Code]....
View 30 Replies
Apr 29, 2010
I have a TextArea html helper method I'm calling in a foreach loop. Basically, when I initially load the View it works fine, but when i reload the View and load postback data, the same TextArea throws a NullReferencException and yet the variable I'm using in the TextArea as the name of the TextArea is not null. I've attached a picture below for demonstration:
if it's difficult to see, the blue arrow below is pointing to the variable used to name the TextArea. Again, it works on initial load, but it errors out on postback when the page is reloaded. I'm not sure what's going on.
View 2 Replies
Jul 15, 2010
I am getting this exception even though no values to my knowledge are null, apart from the model.SuburbID itself.
Here is controller code for getting the suburbs:
[Code]....
Here is the view code:
[Code]...
View 3 Replies
Jan 19, 2010
My controller calls a class in my model which is getting data from a REST web service. The class in the model then passes the data back to the controller using an IList, like so:
[Code]....
My problem is this: The data that is held in the IList isn't there until the user has done a search in the View, submiting a form. This is a basic search function with 2 textboxes and a submit button in a form. When the user clicks submit, the controller action is called, the web service is then called, and the data in the IList gets populated. The problem is that in the View I am using a strongly typed view and my model reference in the foreach loop throws a Null Reference Exception because there is no data in it, because a search has not been conducted yet...
[Code]....
So, how can I have the above foreach loop in my view if there isn't any data in the model until a search has been conducted? Is there a better way that I should be doing this?
Essentially, what's the best method for passing data back to a view that is based on a form submittion?
View 6 Replies
Dec 6, 2010
We have a chart on a page that current is hard coded with test data, client likes and we are trying to now link to live data.I have tried different things in the code behind to build the url and keep getting Null Reference Exception even though when i debug the url is there and complete. I can take the value that i get in debug and paste directly to the browser and the chart works. so i know that im building the url correctly, but setting the .Src of the image in the page_load event doesnt seem to be the correct way to populate the image..Here is the complete link that is built in the code behind that is passed to the src of the image control.http://chart.apis.google.com/chart?hs=300x265&chd=s:bD&chdl=DVDs|DVDs+with+Scracthes&chdlp=b&chl=44|5&chma=40,60,0,40&chtt=DVD+Report&cht=p3&chco=751010|FFCC33 In the page load event i have the following:
[Code]....
[Code]....
I place a break point on the line where i set the src and as i step thru everything is correct and the src is being populate with the correct link, but when i step past that line, then i get the null reference.Now why is it that i can paste that link to the browser and it works.. and if i hardcode that link in the image src on my aspx page and comment out the code behind it works there also..
View 17 Replies
Jun 30, 2010
I am using httpcontext.Current in one my action method and i created the ms test method for testing this action and also i created the Mock object for httpcontect,but when i am trying to run the MS test script i am getting null reference exception from the line which i am using httpcontext.current in the action method.
View 1 Replies