Jump to content

object reference not set to an instase of an obje

Recommended Posts

Hi,it is second time i am posting this Error sorry about it, i have been working on it in 6 days and i am still in the begining.here is my code and the Error is "Object reference not set to an instase of an object" public partial class SearchUC : System.Web.UI.UserControl, ISelectedTitleFeed { private DataSet DS; protected void SearchButton_Click(object sender, EventArgs e) { DS = minWebService(); // a reference to a web service, returns a dataset foreach (DataRow DR in DS.Tables["items"].Rows) { DropDownlist1.Items.Add(DR["title"].ToString()); } } protected void DropDownList1_Changed(object sender, EventArgs e) { string temp = string.empty; foreach (DataRow DR in DS.Tables["items"].Rows) // here i get the error. temp += DR["title"].ToString(); Label1.Text = temp; } }I must say that i click on Button first then i choose a item in the DropDownlist.

Link to post
Share on other sites

The error is in the foreach line of your DropDownList1_Changed function? And I'm guessing that you have tied this to the OnChange event for a dropdownlist on your page.It looks like the error is occurring because the DS is empty when you are calling that function as it is only being filled when you call the SearchButton_Click function.I think you'll need to add the "DS = minWebService()" line to your DropDownList1_Changed function. I think even though you are clicking on the Submit button before changing the dropdownlist, the DS is not filled unless you are calling the DS = minWebService() after the postback.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...