cyrus_ 0 Posted March 21, 2006 Report 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. Quote Link to post Share on other sites
aspnetguy 30 Posted March 26, 2006 Report 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. Quote Link to post Share on other sites
Jorsh 0 Posted March 29, 2006 Report 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. Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.