nullreferenceexception

Get SelectedDataKey in RowDataBound

偶尔善良 提交于 2019-12-13 07:00:18
问题 this code is returning a NullReferenceException since the SelectedDataKey is not selected yet. How can I check if the the DataKey is selected or not.. protected void grdRoles_RowDataBound1(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { CheckBox chk = (CheckBox)e.Row.FindControl("chkRole"); int rolecode = Convert.ToInt32(this.grdRoles.DataKeys[e.Row.RowIndex].Value); BusinessLayer.Customers checkRole = new BusinessLayer.Customers(); bool check =

Iterate/Loop through Datagrid rows to get the value of checkbox column using Silverlight/ c# wpf: NullReferenceException error

南笙酒味 提交于 2019-12-13 06:17:44
问题 I have a DataGrid in Silverlight xaml which contains three columns named Active(checkbox), name(Textcolumn), ID (Textcolumn) and a Save button outside the datagrid. I am getting the following error when I try to loop/iterate through the datagrid rows to get the value of the checkbox using GetCellContent. GetCellContent works fine for first 20 rows but gives the NullReferenceException error after that. Please help. System.NullReferenceException: Object reference not set to an instance of an

Global Structure array gives a NullReferenceException

天大地大妈咪最大 提交于 2019-12-13 05:17:19
问题 Here is the definition of the structure Structure Ct Public name As String Structure Pt Public identity As String End Structure Public Pty() As Pt End Structure Public Cty() As Main.Ct This is declared in a module called main. Then this piece of code, located in a subroutine in another class is run Dim i As Integer = 1 For Each item As String In cataList.Items 'cataList is a listbox Cty(i).name = item i += 1 Next It throws a nullReferenceException. What is missing? I need the structure to be

C#: Null Reference Exception [duplicate]

走远了吗. 提交于 2019-12-13 04:48:49
问题 This question already has answers here : What is a NullReferenceException, and how do I fix it? (29 answers) Closed 3 years ago . public Person[] GetColleagues(String fn, String ln) { string[] data1 = File.ReadAllLines(@"link1") string[] personv = data1[0].Split('$'); string[] data2 = File.ReadAllLines(@"link2"); string[] jobv = data2[0].Split('$'); string[] jobsearch = Array.FindAll(jobv, element => element.Contains(GetJobInfo(fn, ln).companyName)); if (jobsearch.Length>0) { string[]

Deserialized Xml Object Loop Throws NullReferenceException

别等时光非礼了梦想. 提交于 2019-12-13 04:26:29
问题 This is sort of a continuation of another question and all of the code related to this question can be found, Here. I am experiencing a strange NullReferenceException Error that I just can't figure out. I am trying to build a table from a Deserialized web response. When I go to iterate through the object items I hit a NRE. The weird thing is I tested my condition statement by its self and I am able to catch it. Here is my code: public string getExample() { DataTable dt = new DataTable();

Null Reference Exception [duplicate]

有些话、适合烂在心里 提交于 2019-12-13 03:59:37
问题 This question already has answers here : What is a NullReferenceException, and how do I fix it? (29 answers) Closed 3 years ago . This code generates and Null Reference exception. Exception comes at the line where the parameter array is initialized. What can be the problem? I don't know howto follow the stack-trace and work any logic over it. thanks in advance. DAL dal = new DAL(); string SQL = @"INSERT INTO Assets ([AssetName],[AssetType],[Model],[Description], [PurchaseValue],[SalvageValue]

Rare System.NullReferenceException show up for a HttpContext.Current.Session[“courseNameAssociatedWithLoggedInUser”] that was previously populated?

房东的猫 提交于 2019-12-13 03:39:41
问题 Our ASP.NET C# web application is used in the following environment .NET Framework 4 Silverlight 4 / PivotViewer IIS 7 Windows 2008 Visual Studio 2010 .NET IDE C# HTTPS ( SSL ) Our Silverlight 4 / PivotViewer controls are obviously embedded in ASP.NET pages. In rare cases we get the "Object reference not set to an instance of an object. error when navigating around ASP.NET pages that host our Silverlight 4 / PivotViewer modules on our standalone Windows 2008 server with IIS 7. Also, there is

How to Redirect on Session End [duplicate]

风流意气都作罢 提交于 2019-12-13 02:33:46
问题 This question already has answers here : Session_End in Global.asax.cs not firing using forms authentication (3 answers) Closed 4 years ago . I am trying to redirect user to another page when session ends. This code will result "Object reference not set to an instance of an object." exception void Session_End(Object sender, EventArgs E) { HttpContext.Current.Response.Redirect("/"); } any idea how to do it ? 回答1: Session_End is fired internally by the server, based on an internal timer.

MVC NullReferenceException on @foreach (var item in Model)

和自甴很熟 提交于 2019-12-13 00:55:30
问题 I'm getting the below error, after reading through this What is a NullReferenceException, and how do I fix it? I understand what the error is but not how its being caused or how to fix it in my case, Can anyone explain why? Error: System.NullReferenceException: Object reference not set to an instance of an object. Error on line: @foreach (var item in Model) Controller: using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; using System.Web

Test assert fail: Null reference exception. Object Reference not set to an Instance of an object

心不动则不痛 提交于 2019-12-13 00:33:59
问题 Ok so I have one line of code that is causing me grief, but unfortunately without it, my program breaks. It is the only way I can think of (aside from completely restructuring my program) to do what I want it to do. The purpose of this line is to select the next class to run (in the menu), which is outside of its own scope. Trouble is that the class (Login) exists within the scope of the menu. Here is the line: LoginView.Menu.SetMenuView(); Can anyone suggest a better way of writing this?