I use DataGird_ItemCreated Events and a droplist to DataGrid Cell,but I cann't let the droplist have a initial value , even I use SelectedValue property or SelectedIndex property

I use DataGird_ItemCreated Events and a droplist to DataGrid Cell,but I cann't let the droplist have a initial value , even I use SelectedValue property or SelectedIndex property


protected void dgMain_ItemCreated( Object sender, DataGridItemEventArgs e)
{
if( e.Item.ItemType == ListItemType.EditItem)
{
DropDownList ddlPermissionCategory = new DropDownList() ;
ddlPermissionCategory.ID = "ddlPermissionCategory" ;
ddlPermissionCategory.DataSource = Business.AccountsTool.GetCategoryList() ;
ddlPermissionCategory.DataTextField = "Name" ;
ddlPermissionCategory.DataValueField = "ID" ;
ddlPermissionCategory.SelectedValue = mEditCategoryID ; ddlPermissionCategory.SelectedIndex = 1 ;
ddlPermissionCategory.DataBind() ;

e.Item.Cells[3].Controls.Add(ddlPermissionCategory) ;
}
/*
if(e.Item.ItemType == ListItemType.Item)
{
e.Item.Cells[2].Text =
}
*/

}
0
idiot
11/24/2004 2:18:39 AM
asp.net.presentation-controls 72751 articles. 3 followers. Follow

2 Replies
506 Views

Similar Articles

[PageSpeed] 37

You need to set the SelectedIndex after you DataBind the DDL. Also, in case you want to select an entry in the DDL based on the datasource of the DataGrid, you need to move your code from ItemCreated to ItemDataBound
Bug [MCSD]
0
Bug_Bugger
11/24/2004 1:00:52 PM
let me try and thanks
0
idiot
11/27/2004 10:52:40 AM
Reply: