0

I have a ListView control, I want to edit the InsertItem Template to include a Dropdownlist Item which contains a list of users in Membership Directory.

I tried this:

    MembershipUserCollection users = Membership.GetAllUsers();

    assigned_volunteerDropDownBox.DataSource = users;
    assigned_volunteerDropDownBox.DataBind();

The biggsest issue is that it says assigned_volunteerDropDownBox does not exist in the current context... In fact none of the TextBox items on the insert template are in the current context (is this normal)?

How would I go about doing this? I want to be able to only allow the row to be updated with valid usernames.

I looked at this, but it doesn't actually contain the code to DataBind to the DropDownList item.

Community
  • 1
  • 1
Ray Suelzer
  • 4,026
  • 5
  • 39
  • 55

2 Answers2

1

You could access the assigned_volunteerDropDownBox from code behind; but it's probably easier to do the binding from the drop down control itself. Create a property to bind to:

// lazy-loaded property
public MembershipUserCollection UsersCollection
{
    get
    { 
        if (_usersCollection == null)
        {
            _usersCollection = Membership.GetAllUsers();
        }
        return _usersCollection;
    }
}
MembershipUserCollection _usersCollection;

Then use DataSource on the DropDownList:

<asp:DropDownList RunAt="Server" DataSource=<%# UsersCollection %> ID="assigned_volunteerDropDownBox" />
McGarnagle
  • 101,349
  • 31
  • 229
  • 260
0

You need to use FindControl to find controls in a template.

Michal Klouda
  • 14,263
  • 7
  • 53
  • 77