cyrus_ Posted March 21, 2006 Share Posted March 21, 2006 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 comment Share on other sites More sharing options...
aspnetguy Posted March 26, 2006 Share Posted March 26, 2006 we'll need to see the full code...please tell us which line is causing the error.This will help give a quicker solution. Link to comment Share on other sites More sharing options...
Jorsh Posted March 29, 2006 Share Posted March 29, 2006 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 comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now