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

帮小弟看下这段代码:gridview模板列绑定dropdownlist出问题了~~~
[code=C#][/code] 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); “输入字符串的格式不正确。”


------解决方案--------------------
错误:int iDCIDTemp =Convert.ToInt32 ( hfd1.Value); “输入字符串的格式不正确。” 
//////////
在那里设个断点,看看读到的hfd1.Value的值是什么.
------解决方案--------------------
有可能hfd1.Value没有办法转化为int
------解决方案--------------------
hfd1.Value 不全部是数字,所以无法强制转换