public void sh_configration_Update(Object sender, DataGridCommandEventArgs e) 
{
string city = ((TextBox)e.Item.Cells[1].Controls[1]).Text;
string price = ((TextBox)e.Item.Cells[2].Controls[1]).Text;
string quickprice = ((TextBox)e.Item.Cells[3].Controls[1]).Text;
SqlConnection connUpdate = new SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"]);
connUpdate.Open();
String sql_edit = "UPDATE sh_configration " +
"SET city = '" + city.Replace("'","''")+ "'," +
"price = '" + price.Replace("'","''")+ "'," +
"quickprice = '" + quickprice.Replace("'","''")+ "'" +
" WHERE id = " + e.Item.Cells[0].Text;SqlCommand sqlCommandUpdate = new SqlCommand(sql_edit,connUpdate);
sqlCommandUpdate.ExecuteNonQuery();
connUpdate.Close();sql =  "Select * FROM sh_configration where isvalid=0";
sh_configration.EditItemIndex = -1;
sh_configration.DataSource = CreateDataSource();
sh_configration.DataBind();}
这是一段更新事件,怎么样在这里判断price和quickprice只能为数字,否则弹出类似Javascript的提示框

解决方案 »

  1.   

    IF isnumberic(price)=false then
    response.write("<script>alert('no')</script>")
    exit 
    end if
      

  2.   

    if price不全数字或quickprice不全数字
    {
       response.write("<script>window.alert('只能为数字!')</script>")
       return;
    }
      

  3.   

    try
    {
    pricee = int.Parse(price);
    quickpricee = int.Parse(quickprice);
    }
    catch
    {
     Response.Write("输入只能为数字");
    }
      

  4.   

    IF isnumberic(price)=false then
    response.write("<script>alert('no')</script>")
    exit 
    end if
    能告诉我这一句具体应该加在哪里吗??最好是针对我上面的程序来说
      

  5.   

    你这个Price是从DataGrid来的,修改时放在下面语句后
    string city = ((TextBox)e.Item.Cells[1].Controls[1]).Text;
    string price = ((TextBox)e.Item.Cells[2].Controls[1]).Text;
    string quickprice = ((TextBox)e.Item.Cells[3].Controls[1]).Text;
    你最好在增加的时候也判断一下
      

  6.   

    在DataGrid中的price列中用正则表达式,控制不能输入其它字符,这里就不用判断了
      

  7.   

    /* 数字检验 *///|| window.event.keyCode == 16 //Shift键
    function keydownevent(){
    if((window.event.keyCode>95 && window.event.keyCode<106) //小键盘的数字键
    || (window.event.keyCode>47 && window.event.keyCode<59 && window.event.keyCode!=16) //大键盘的数字键
    || window.event.keyCode == 8 //退格键
    || window.event.keyCode == 9 //Tab键
    || window.event.keyCode == 13 //回车

    || window.event.keyCode == 46 //Delete功能键
    || window.event.keyCode == 37 //左移键头
    || window.event.keyCode == 39) {
    }
    else {
    window.event.returnValue =0;
    return false;
    }
    }