后台判断格式是否想要的类型可使用 try{} catch{}捕获错误,

来源:互联网 发布:淘宝好评返现被投诉了 编辑:程序博客网 时间:2024/06/05 02:13
 

    protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
    
   shipped_list rowupdat = new shipped_list();
   string Ror_id = ((Label)this.GridView1.Rows[e.RowIndex].FindControl("ID_R")).Text.ToString();//
   string Price = ((TextBox)GridView1.Rows[e.RowIndex].FindControl("Price")).Text.ToString();//     
   string Invoice_no = ((TextBox)GridView1.Rows[e.RowIndex].FindControl("Invoice_no")).Text.ToString();//

   string Invoice_date = ((TextBox)GridView1.Rows[e.RowIndex].FindControl("Invoice_date")).Text.ToString();

   string TKUQ_PO = ((TextBox)this.GridView1.Rows[e.RowIndex].FindControl("TKUQ_PO")).Text.ToString();//

   string PayDate = ((TextBox)this.GridView1.Rows[e.RowIndex].FindControl("PayDate")).Text.ToString();//
   Hidden_num.Value = Price.ToString().Trim();
    //ScriptManager.RegisterStartupScript(this, typeof(string), "js", "type_button2()", true);
    if (Price == "")

        { Price = "0"; }
        string type_1 = "RowUpdat";

        float Price_s = 0;
        try
        {
            Price_s = float.Parse(Price);

            if (rowupdat.RowUpdat_se(Invoice_date, Price_s, Invoice_no, TKUQ_PO, PayDate, Ror_id, type_1, type_1))
            {
                ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "alert", " <script>window.alert('更新成功!'); </script>", false);
            }
            else
            {
                ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "alert", " <script>window.alert('更新失败!'); </script>", false);
            }

        }
        catch
        {
            ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "alert", " <script>window.alert('更新失败!单价格式错误!'); </script>", false); ;
        }

 

 

 

        float Price_s = 0;
    
    try
        {
            Price_s = float.Parse(Price);
        }
        catch
        {
            ScriptManager.RegisterClientScriptBlock(this.Page, this.GetType(), "alert", " <script>window.alert('更新失败!单价为数字类型错误!'); </script>", false); ;
        }

 

 

原创粉丝点击