NinetyNine's Treasure

| 积淀*育创新 智慧创造价值|

导航

DataGrid内绑定DropDownList

Posted on 2007-09-15 02:30  (NineTyNine)  阅读(339)  评论(0编辑  收藏  举报
private void dg_Class_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
        
{
            
string SqlSelect = "select dep_id,dep_name,dep_code from db_dep";
            
if(e.Item.ItemType==ListItemType.EditItem)
            
{
                DropDownList DDLinDG 
= (DropDownList)(e.Item.FindControl("ddl_depnameInDG"));
                DDLinDG.DataSource 
= NN.ds(SqlSelect).Tables[0];
                DDLinDG.DataValueField 
= "dep_id";
                DDLinDG.DataTextField 
= "dep_name";
                DDLinDG.DataBind();
                DDLinDG.Items.FindByText(Convert.ToString(DataBinder.Eval(e.Item.DataItem,
"dep_name"))).Selected=true;
            }

        }