I am making a class with an optional paramiter which will be a List<> paramiter. I want to set it's default value to null so I have used List<Params> Param = null. What am not 100% sure is checking the list to see if it was set to null or not. Is using:
protected void rptNavigation_ItemDataBound(object sender, System.Web.UI.WebControls.RepeaterItemEventArgs e){ if (!((e.Item.ItemType == ListItemType.AlternatingItem) || (e.Item.ItemType == ListItemType.Item))) {return; }string Name = string.Empty; if (IsDBNull(e.Item.DataItem["FullName"])) { Name = String.Empty;} else {Name = (string)(e.Item.DataItem["FullName"]);} Literal ltlLiteral = (Literal)(e.Item.FindControl("ltlLiteral")); ltlLiteral.Text = Name.ToString();
I get error for IsDbNull - Error 1 The name 'IsDBNull' does not exist in the current context. What's the best way to check for null values returned from db? also I get errors on both lines where (e.Item.FindControl(ltlLiteral")); is present ERror: Cannot apply indexing with [] to an expression of type 'object'
.NET noob here (as in I know next to nothing, I'm trying to pick up some of the scraps left by my developer). Ok, I am getting this error on a number of my .aspx pages: Error while checking url '/': Key cannot be null. Parameter name: key Interestingly, I get this on my homepage on which the only .NET code is in the form of two includes, e.g: <% Response.WriteFile("/includes/footer.aspx") %> These includes in themselves only contain HTML, so I assume the issue can only be related to these or a configuration issue?
I use the following code to get the file name out of the URL.
[Code]....
This works fine if there is actually a page that shows up after a '/', I would also like to check for when there is nothing showingup after the '/'. My alert above shows nothing to be there, but how do I chack for the nothing. I have tried the folloiwng, but for some resaon it just ignores me. If I do an if statement, it doesn't pick up that there isn't anything there.
if (sPage = '') { alert(sPage);}
Even though there isn't anything there, it won't show the alert and acts as if there is actually something there.
Is there one simple test that a person can do that covers all options where there could be a null, or "" value. When I google, I see so many options. I see:
if txtBox1.text IsNot nothing if txtBox1.text.toString isNot nothing if txtBox1.text <> "" if txtBox1.text.toString <> "" if isNull(txtBox1) Is there on test that can cover them all?
I have a no. of records being inserted in a List<>.I have IQueryable returning more then one recordI want to check whether the records IQueryable returns are present in the list or not?
I have a FormView that is loaded with a records from my DB. Some of the fields may be blank or null. I am trying to check the value of some of the text boxes to verify that the user has updated the fields prior to allowing a DB update from the Edit Template.
I can not seem to get the correct syntax on the if statment to check the value of the text box....
I was wondering if there is any way that I could have a null value (or any other static value) appear at the top of a drop down list which is then populated from an AccessDataSource.I need it so that users can select a tag for their post (within a social networking system) if they wish to post to a group page or they can simply leave the list as null to post to their profile.
I am converting my datatable to LISt using LINQ how do I handle nulls coming from database
List<Port> portDetails = new List<Port>(); DataTable dt = ds.Tables[0]; portDetails = (from q in dt.AsEnumerable() select new Port { PortCode = q.Field<string>("Code"), ExtCode = q.Field<string>("Nb"), Name = q.Field<string>("Name")) }).ToList();
In the above query if Code is null I do not want property portcode to be set to the value it should only set if it is not null or not blank PortCode = q.Field<string>("Code"),
What should be syntax I was trying somethign like this which doesnt work Portcode = q.Field<bool>("Code") == null ? null : q.Field<bool>("Code")
I am attempting to bind data from a dropdown list that was populated from another datasourceID. I've bolded what I believe is relevant to this issue in the code below. But basicly its binding the proper county on the pull down menu but when I hit form submit it dosnt postback that info instead its null.
public class WebModel { public List<ArticleModel> Articles { get; set; } } public class ArticleModel { public int ID { get; set; } public double ValueParam { get; set; } }
Then I have the controller with the two actions:
[Authorize] public ActionResult Index() { WebModel model = new WebModel(); ModelConverter.ConvertToModel(model, controller); return View(model); } [Authorize] [HttpPost] [ValidateInput(false)] public ActionResult Index(WebModel model, string saveButton) { ModelValidation.ValidateWebModel(model, ModelState); if (ModelState.IsValid) { return RedirectToAction("Create", "Article"); } ModelConverter.ConvertToModel(model, controller); return View(model); }
If I press the submit button, I get to the second action method in the controller (the one with the HttpPost attribute). In this action, the object model itself is not null, but the "Articles" list inside is null.
I am declaring a list in my class, populating the list in page load and using the list in various methods in this class. But, I get this error at every instance where I use this list in the methods. Error: System.NullReferenceException: Object reference not set to an instance of an object.
I have setup my business object to have a create_date and edit_date members both datetime datatypes. My company want to display the create_date and edit_date fields in a gridview for each transaction. The problem i have is that after insterting a record it will have a valid create_date but no edit_date and when displayed in the gridview it defaults to datetime.minvalue (My default). How on earth do i show an empty field in my gridview for a null datetime field in the database?
I am using similar architecture to the Imar Spaanjaars example of a tiered solution. With a few small tweeks it has worked well for me for ages. I am passing a List<Database> to my object datasource which connects to my gridview.
I have a stored procedure to insert data into Table B, but when I tried to insert a null value into column ID of table B, this error came up:
The INSERT statement conflicted with the FOREIGN KEY constraint "FK_tableB_tableA". The conflict occurred in database "database name", table "table A", column 'ID'.
I am guessing adding nothing to the null value column is the problem, but i don't know how to fix it... The INSERT statement conflicted with the FOREIGN KEY constraint "FK_tableB_tableA". The conflict occurred in database "database name", table "table A", column 'ID'.
I have a problem with a SessionVariable. I will explain what is happening:
1. From the default.aspx I send Session["LoginByAdmin"] = "Dummy"; and then redirect to this page where I have the code below. So the Page_Load sees that this Session["LoginByAdmin"] != null and enter this page. This works fine !
2. In the Page_Load, I later fill a ListBox1 with foldernames.
3. With Button1_Click1, I will now delete the choosen Folder in the ListBox1 wich works fine the first time and the ListBox updates the new existing folders in the ListBox. (I have wrapped this inside an updatepanel)
The problems comes now when I try to delete a choosen folder in the ListBox1 the second time in a row. When I select a Folder in the ListBox1 and now Press Button1, I will be redirected to "Default.aspx". This meens that this code is running: (That meens that Session["LoginByAdmin"] == null and I have not set this to null anywhere. This is my big question how this variable can be = null here?
if (Session["LoginByAdmin"] == null) Response.Redirect("Default.aspx"); break;
I am using dropdownlist in my view page with some values which will display corresponding ID(primary key of other table) in my database.If i leave my dropdownlist blank and save it in database then its showing null parameter error. Can you explain how to use this reference type to overcome this error
In my code behind, I have the following code that I want to insert a null value for a parameter. Instead of doing that, it is adding the word "NULL" to my database. What am I doing wrong?