views:

32

answers:

2

I have a table the uses the same dropdown list in each row. I thought that I could just create one dropdown list and then reuse it in each new row, but the table only ends up with one row unless I create "new" dropdownlist. Am I approaching this all wrong?

In the interest of efficiency, is there a way to build the list once and then reuse it by creating another instance of it or something? I was trying to avoid rebuilding that list umpteen times.

Thanks

private void UserRoles()
{
    Table table = MakeTable();
    Ewo.sqlDataStore.Administrator sql = new Ewo.sqlDataStore.Administrator();
    DataSet dataset =sql.SiteUserRoleList();
    DropDownList sel = RoleList(dataset.Tables[0]);
    if(tools.validDataSet(dataset))
    {
        if (dataset.Tables.Count > 1)//existing roles are #2, show the roles the user is part of
        {
            foreach (DataRow dRow in dataset.Tables[1].Rows)
            {
                table.Rows.Add(CreateRoleRow(Convert.ToString(dRow["SitePageGroupName"]), sel));//add a row with data
            }
        }
        table.Rows.Add(CreateRoleRow(sel));//add a blank row on the bottom
    }
    AdminSiteUerRoles.Controls.Add(table);//add it all to the page
}
A: 

Could you perhaps convert your table into an asp:GridView?

Otherwise, perhaps you could load your DropDownLists via a SqlDataSource or ObjectDataSource.

Create a new DropDownList() and add to your table's column as needed.

Specify the DataSourceID for each new DropDownList to be the datasource.

p.campbell
Thanks for the gridview suggestion but I am doing too many other funky things to make that feasible.
Praesagus
A: 

Hi Praesagus,

You should create new DropDown instance for each row.

Here is an example:

foreach (DataRow dRow in dataset.Tables[1].Rows){
DropDownList sel = RoleList(dataset.Tables[0]);
    table.Rows.Add(CreateRoleRow(Convert.ToString(dRow["SitePageGroupName"]), sel));

}

Hope this helps...

Muse VSExtensions
That does make it work - thanks. In the interest of efficiency, is there a way to build the list once and then reuse it by creating another instance of it or something? I was trying to avoid rebuilding that list umpteen times. RoleList(dataset.Tables[0]) will recreate the list.
Praesagus