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

本文介绍了一个ASP.NET中GridView控件RowUpdating事件处理的示例代码,演示了如何从GridView获取用户编辑的数据,并进行数据验证及更新操作。
 

    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); ;
        }

 

 

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

那小x的传说

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值