日期:2014-05-18  浏览次数:20682 次

运行到DropDownList处有问题
编辑页面的所有文本框和时间控件还有下拉列表都放在一个DetailView中,当进入编辑页面时,在.cs后台代码页中有如下代码   DropDownList   ddl   =   (DropDownList)DetailsViewFile.Rows[0].FindControl( "dropCategory ");
ddl.DataSource   =   MediaCategories.GetInfoByCategoryID(category.ParentID);
ddl.DataBind();
ddl.SelectedValue   =   file.CategoryID.ToString();
对第一行代码提示 "索引超出范围。必须为非负值并小于集合大小。\r\n参数名:   index ",这是怎么回事,源代码部分
  protected   void   Page_Load(object   sender,   EventArgs   e)
        {
                if   (!IsPostBack)
                {
                        int   id   =   0,   cid   =   0;
                        try
                        {
                                id   =   int.Parse(Request[ "id "]);//用来判断它是添加还是修改
                                ViewState.Add( "id ",   id);
                                cid   =   int.Parse(Request[ "cid "]);//上个list文件传过来的     categoryID,用来确定添加的文件属于哪个类别
                                ViewState.Add( "cid ",   cid);
                        }
                        catch
                        {
                                this.GoError( "页面错误 ",   "无效的参数或链接错误。 ");
                        }
                        if   (id   >   0)                                   //修改
                        {
                                DetailsViewFile.DataSource   =   MediaFile.GetListByCategoryID(id);
                                DetailsViewFile.DataBind();
                                MediaFile   file   =   new   MediaFile(id);
                                MediaCategories   category   =   new   MediaCategories(file.CategoryID);