Will not work
I'm using the following function to load dropdownlist on Edit ( <ItemTemplate>)
protected void lvBackupLog_ItemDataBound(object sender, ListViewItemEventArgs e)
{
ListViewDataItem dataItem = (ListViewDataItem)e.Item;
System.Data.DataRowView dv = (DataRowView)dataItem.DataItem;
DropDownList ddlServer = (DropDownList)e.Item.FindControl("backup_server_nameDDL");
DropDownList ddlTape = (DropDownList)e.Item.FindControl("backup_tape_nameDDL");
if (ddlServer != null)
{
DataSet dsServerList = new DataSet();
DataLib.BackOffice_Open();
BackOffice.aGetServerList(ref DataLib, ref dsServerList);
DataLib.BackOffice_Close();
ddlServer.DataSource = dsServerList;
ddlServer.DataTextField = "backup_server_name";
ddlServer.DataValueField = "backup_server_id";
ddlServer.SelectedValue = dv.Row["backup_server_id"].ToString();
ddlServer.DataBind();
}
}
It will populate DropDownList and will select correct items
To make it work for InsertItemTemplaet use the following
protected void lvBackupLog_ItemCreated(object sender, ListViewItemEventArgs e)
{
DropDownList ddlServer = (DropDownList)e.Item.FindControl("backup_server_nameDDL");
DropDownList ddlTape = (DropDownList)e.Item.FindControl("backup_tape_nameDDL");
if (ddlServer != null)
{
DataSet dsServerList = new DataSet();
DataLib.BackOffice_Open();
BackOffice.aGetServerList(ref DataLib, ref dsServerList);
DataLib.BackOffice_Close();
ddlServer.DataSource = dsServerList;
ddlServer.DataTextField = "backup_server_name";
ddlServer.DataValueField = "backup_server_id";
ddlServer.DataBind();
}
}
There is no need (and no way) to select item from database as this is new item. You can of course default it to something
Populate listview from data in C#.NET
ReplyDelete