Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Weird problem with ListBox databinding
Message
De
19/08/2003 00:22:11
 
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Divers
Thread ID:
00821270
Message ID:
00821274
Vues:
18
OK, just guessing here ... what exactly is Lookups? Custom DataAccess class or something? I'm guessing that's the case because Lookups.Execute() and Lookups.ExecuteNonQuery() belong to the SqlCommand namespace, but Lookups.DataSet does not. So, you've got a custom class. Do you delete anything from the actual DataSet before sending the updates to the backend? That can sometimes result in the error you're seeing. Which statement is causing the error?

~~Bonnie

>Ok I seem to be loosing my mind, maybe somebody can set me straight here <g>...
>
>I have a ListBox on a Web Form which is bound by data in a DataSet. I have a method on the form that loads the data and populates the listbox. It works just fine when I show the form for the first time. You can add and delete items which adds and deletes items from the database.
>
>When I display it works. When I add it works. When I delete I get an error:
>
>Specified argument was out of the range of valid values. Parameter name: value
>
>The weird thing is that I *always* reload the data the same way. So if the data was changed should have absolutely no effect on the databinding. The method does this:
>
>
>private bool LoadLookups()
>{
>	if (Lookups.Execute("select cData1 as Category from wws_lookups where type='CATEGORY' order by 1","TCategories") < 0)
>	{
>		this.lblErrorMessage.Text = "Couldn't load data items: " + Lookups.ErrorMsg;
>		return false;
>	}
>
>	this.lstCategoryList.DataSource = Lookups.DataSet.Tables["TCategories"];
>	this.lstCategoryList.DataValueField = "Category";
>	this.lstCategoryList.DataTextField = "Category";
>
>	this.lstCategoryList.DataBind();
>
>	return true;
>
>
>and it's called from the various other form event methods. The process in Delete is something like this:
>
>
>private void btnDelete_Click(object sender, System.EventArgs e)
>{
>	string lcValue = Request.Form["lstCategoryList"];
>
>	if (Lookups.ExecuteNonQuery("delete from " + Lookups.Tablename + " where cData1='" +lcValue + "'") < 1)
>	{
>		this.lblErrorMessage.Text = "Category not deleted: " + Lookups.ErrorMsg;
>	}
>	else
>	{
>		this.lblErrorMessage.Text = "Category deleted.<br>" +
>					                "Note: the change may not immediately take as the category list is cached.";
>	}
>	this.lstCategoryList.SelectedValue = ".Net";
>	this.LoadLookups();
>}
>
>
>Note that LoadLookups() is called at the very end.
>
>I've made certain that the DataTable bound to exists. I've checked all the rows in the table to make sure the values are good. I've actually iterated over the whole table and printed it out. It all looks good. But it fails after a Delete operation.
>
>If I reload the page it loads fine.
>
>What could possibly be causing this to fail? Basically the list is only loaded on the delete operation, since Page_Load() only loads the data if there's no PostBack. The same exact procedure is used when data is added and it works.
>
>I'm stumped. FOr kicks here's the Add code which is nearly identical.
>
>
>private void btnAdd_Click(object sender, System.EventArgs e)
>{
>	int SortOrder = 0;
>	try
>	{
>		Int32.Parse(this.txtSortOrder.Text);
>	}
>	catch(Exception)
>	{
>		SortOrder=0;
>	}
>	
>	
>	if (Lookups.ExecuteNonQuery("insert into " + Lookups.Tablename + " (type,cData1,iData,cData,cData2) values ('CATEGORY','" +
>			this.txtCategory.Text +"'," + SortOrder.ToString() + ",'','')" ) < 0)
>		this.lblErrorMessage.Text = "Couldn't add Category: " + Lookups.ErrorMsg;
>	else
>	{
>		this.lblErrorMessage.Text = "Category added.";
>		this.LoadLookups();
>		this.txtSortOrder.Text="0";
>		this.txtCategory.Text="";
>	}
>
>	this.LoadLookups();
>}
>
Bonnie Berent DeWitt
NET/C# MVP since 2003

http://geek-goddess-bonnie.blogspot.com
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform