代码改变世界

下拉菜单DropDownList无法插入项 Items.Insert unavailable

2009-09-01 15:14  Fred-Xu  阅读(1011)  评论(2编辑  收藏  举报
这个问题我想一般开发人员很少会遇到,但偏偏被我的粗心大意给遇到啦。
情况是这样:我先给DropDownList控件绑定了数据源,然后用DropDownList.Items.Insert(0,new ListItem("全部...",""))插入一条项,但是经过N出调整和编译,始终无法显示新插入的那条“全部...”到DropDownList中。

原先的代码如下:
protected void Page_Load(object sender, EventArgs e)
        {
            
if (!IsPostBack)
            {
                Uni.TransLanguage(
this.Controls);
                Uni.bindDropDownList(ddlType, 
"type_information_res""res");
                
this.ddlType.Items.Insert(0new ListItem("全部"""));

                BindData();
            }
        }

        
// 绑定数据
        protected void BindData()
        {
            ServiceRefInfo.DbInfoAccessClient client 
= new tcShare.ServiceRefInfo.DbInfoAccessClient();
            
string strWhere = "status=1 and dict_type='type_information_res' and dict_type2='type_information_res'";
            AspNetPager1.RecordCount 
= client.GetImDdResListRecordCount(strWhere);
            gvDocResList.DataSource 
= client.GetImDdResList(AspNetPager1.PageSize, AspNetPager1.CurrentPageIndex, strWhere);
            
this.DataBind(); 

            client.Close();
        }

问题所在:原来是GridView进行DataBind()的时候,我写成了this.DataBind();编译竟然可以通过!列表什么都可以显示,期待高手给与解释。