Hi. I have an aspx page that has two list boxes defined on it. The first list box is populated from a stored procedure. What I am trying to do is when a user selects list items from the populated list box, then clicks the add item button, the code in the code behind page will add the list item to the second listbox and delete it from the first listbox.
My problem is that when I build the project I get errors that say:
"The name 'lstAllLinkCats' does not exist in the current context"
I have searched for the answer and have tried several different things but I cannot resolve this... please help.
I need to figure out why when I do a build my project does not find these controls.
There is a label on the same page that is referenced in the codebehind and it is found but not these two list boxes.
The things I have tried are:
- cleaning the solution prior to build
- adding listbox ld = new lixtbox(); (this gets rid of the error but does not allow me to add or delete or find the selected items from the aspx - I think this is a different listbox instance)
- tried using page.findcontrol - (returns null BUT it the control is in the list)
- created a new project and moved the code over to make sure it was not the solution or project itself.
I am including the code from the aspx page and the cs page below...
.cs code:
using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class admin_AddLink : System.Web.UI.Page
{
if (e.Exception == null)
{
lblStatus.Text = "The link listing was successfully added.";
}
else
{
lblStatus.Text = "There was an error addingthe Link listing.";
}
}
for (int i = 0; i < this.lstAllLinkCats.Items.Count; i++)
{
if (!lstAllLinkCats.Items[i].Selected)
{
lstLinkCats.Items.Add(lstAllLinkCats.Items[i].Value);
lstAllLinkCats.Items.Remove(lstAllLinkCats.Items[i].Value);
}
}
break;
}
case "RemoveItems":
{
for (int i = 0; i < lstLinkCats.Items.Count; i++)
{
if (lstLinkCats.Items[i].Selected)
{
}
}
break;
}
case "AddAllItems":
{
for (int i = 0; i < lstAllLinkCats.Items.Count; i++)
{
if (lstAllLinkCats.Items[i].Selected)
{
}
}
break;
}
case "RemoveAllItems":
{
for (int i = 0; i < lstLinkCats.Items.Count; i++)
{
if (lstLinkCats.Items[i].Selected)
{
}
}
break;
}
}
}
}
If the FormView control acts anything like the ListView control, any controls that are inside the "EditItemTemplate" or "InsertItemTemplate" are not available to the server.
For you to have access to controls, they cannot be inside of the EditItemTemplate or InsertItemTemplate. they need to either be inside the LayoutTemplate(which is probably not what you want) or outside of the FormView all together.
This is all assuming the FormView works the same as the ListView. I haven't used the FormView, but I have used the ListView and I ran into the same problem.
Bookmarks