0
if (((LinkButton)GridView1.Rows[0].Cells[1].Controls[0]).Text == "Insert")
{
VendorProperties VP = new VendorProperties();
VP.VendorName = ((TextBox)GridView1.Rows[0].Cells[3].Controls[0]).Text.ToString();
try
{
VP.ABN = Convert.ToInt32(((TextBox)GridView1.Rows[0].Cells[4].Controls[0]).Text.ToString());
}
catch
{
lblMessage.Text = "Please Enter a Number for ABN";
}
VP.VendorAddress1 = ((TextBox)GridView1.Rows[0].Cells[5].Controls[0]).Text.ToString();
VP.VendorAddress2 = ((TextBox)GridView1.Rows[0].Cells[6].Controls[0]).Text.ToString();
VP.VendorAddress3 = ((TextBox)GridView1.Rows[0].Cells[7].Controls[0]).Text.ToString();
VP.State = ((TextBox)GridView1.Rows[0].Cells[8].Controls[0]).Text.ToString();
VP.PostCode= ((TextBox)GridView1.Rows[0].Cells[9].Controls[0]).Text.ToString();
VP.ContractorVendorContactName = ((TextBox)GridView1.Rows[0].Cells[10].Controls[0]).Text.ToString();
VP.Phone = ((TextBox)GridView1.Rows[0].Cells[11].Controls[0]).Text.ToString();
DropDownList DR = (DropDownList)GridView1.Rows[0].Cells[12].FindControl("DropDownList1");
VP.EmailAddressID= Convert.ToInt32(DR.SelectedValue.ToString());
PinDicDAO.InsertVendor(VP);
}
위의 코드는 gridview 행 업데이트 이벤트를 통해 데이터베이스 레코드를 삽입하는 코드입니다. 항목 "VP.ABN"(try catch 내부)은 정수이고 사용자는 정수를 입력해야합니다. 사용자가 ABN에 대한 문자열을 입력하면 데이터베이스에 레코드 삽입을 중지하고 "다음을 입력하십시오. ABN ".이 코드에서 사용자가 메시지를 표시하는 문자열을 입력하고 ABN 값이 0 인 경우에도 여전히 레코드가 데이터베이스에 삽입됩니다. 어떻게 해결할 수 있습니까?GridView 행 업데이트