string DropDownListState="";
        string sidtostring = "";
        DataListItem dli = (sender as Button).NamingContainer as DataListItem;
        DropDownList DropDownListvalue = (sender as Button).NamingContainer as DropDownList;        if (dli != null)
        {
            Label lab = dli.FindControl("Label1") as Label;            if (lab != null)
            {
                sidtostring = lab.Text;
            }
        }        if (DropDownListvalue != null)
        {
            DropDownList DropDownListdo = DropDownListvalue.FindControl("DropDownList1") as DropDownList;            if (DropDownListdo != null)
            {
                DropDownListState = DropDownListdo.SelectedValue.ToString();
            }
        }
      try
        {
            string strConn = "server=(local);uid=sa;pwd=123456;database=test_user";
            SqlConnection conn = new SqlConnection(strConn);            conn.Open();
            string strSql = "update OrderSend set send_='"+DropDownListState+"' where id='"+sidtostring+"'";
            SqlCommand myCommand = new SqlCommand(strSql, conn);
            myCommand.ExecuteNonQuery();        }
        catch (Exception ex)
        {
            Label2.Text = ex.ToString();
        }
System.Data.SqlClient.SqlException: 在将 varchar 值 'Label' 转换成数据类型 int 时失败。
怎么将Label转换成int值啊?
请高手指点一下,  我觉得好像是这句有问题      DataListItem dli = (sender as Button).NamingContainer as DataListItem;但是又不知道怎么改..怎么将转成int啊?

解决方案 »

  1.   

    sidtostring:Label
    id:int 型
      

  2.   

    你的sidtostring="Label" 
    sidtostring 的值是STRING ,不能转换成INT
      

  3.   

    单步看看sidtostring值字符型
    数据库中id int型
      

  4.   

    断点看看
    lab.Text;
    这个的值是多少你要符合整型才能转换的
      

  5.   

    支持4楼
    string 型不能转换int的
      

  6.   

    数据转换的前提,是至少看上去是可以相互转换的,或者有具体规定如何转换。撇开程序不说,lable 这几个字母,lz觉得从数学上说等于数字几?你的代码看上去,是一个列表里,用一个隐藏的Lable1标签来保存数据的主键。那么这么看来,你就是没做数据绑定。aspx中,别忘了个DataList里的Label1标签的Text属性加上绑定
    <asp:Label id="Label1" Text='<%#Eval("ID")%>' />