protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
    {
        //绑定所属区域;
        SqlConnection myconnection = new SqlConnection(sqlconn);
        SqlCommand mycommand = new SqlCommand("iDCIDConvert", myconnection);
        mycommand .CommandType =CommandType .StoredProcedure ;
        mycommand.Parameters.Add(new SqlParameter("@iDCID", SqlDbType.Int, 4));
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            HiddenField  hfd1 = (HiddenField)e.Row.FindControl("HiddenField1");
            int  iDCIDTemp =Convert.ToInt32 ( hfd1.Value);
            mycommand.Parameters["@iDCID"].Value = iDCIDTemp;
            myconnection.Open();
            SqlDataAdapter da = new SqlDataAdapter(mycommand);
            DataSet ds = new DataSet();
            DropDownList ddl1 = (DropDownList)e.Row.FindControl("DropDownList1");
            da.Fill(ds, "basic_DistrictClass");
            ddl1.DataSource = ds.Tables["basic_DistrictClass"].DefaultView;
            ddl1.DataTextField = "cDCName";
            ddl1.DataValueField = "iDCID";
            ddl1.DataBind();
            myconnection.Close();
        }
       
    }-----------------------------------------------------------------------------
错误:int  iDCIDTemp =Convert.ToInt32 ( hfd1.Value);  “输入字符串的格式不正确。”

解决方案 »

  1.   

    错误:int  iDCIDTemp =Convert.ToInt32 ( hfd1.Value);  “输入字符串的格式不正确。” 
    //////////
    在那里设个断点,看看读到的hfd1.Value的值是什么.
      

  2.   

    有可能hfd1.Value没有办法转化为int
      

  3.   

    hfd1.Value 不全部是数字,所以无法强制转换
      

  4.   

    找到原因了,我写到  protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {}事件中问题解决了;
    在GridView1_RowCreated事件中HiddenField还未绑定值,所以.....