Hai
why u go for javascript ? in ur check place (exceeds 1 or not) u use if condition and show ur web message or proceed ur update query.like this
str1 = "select ISNULL(sum(MBO_Weighting_Factor),0) from tbl_MBO_Objective_Details where MBO_Req_Id is null and MBO_EMP_CODE='" & EMP_NO & "'"
Comm1 = New SqlCommand(str1, Conn)
Conn.Open()
sum = Comm1.ExecuteScalar()
Conn.Close()
If (sum > 1)Then
showmessage("Your weghting factor total exceeds you can not
update the record")
Exit Sub
Else
Dim LblID As Integer = DirectCast(GridViewMBOFuncObjDetalis.Rows(e.RowIndex).FindControl("lblEditID"), Label).Text
Dim txtfuncobj As String = DirectCast(GridViewMBOFuncObjDetalis.Rows(e.RowIndex).FindControl("txtfuncobj0"), TextBox).Text
Dim txtmeasuredvar As String = DirectCast(GridViewMBOFuncObjDetalis.Rows(e.RowIndex).FindControl("txtmeasuredvar0"), TextBox).Text
Dim txtdeadline As String = DirectCast(GridViewMBOFuncObjDetalis.Rows(e.RowIndex).FindControl("txtdeadline0"), TextBox).Text
Dim txtweight_fact As String = DirectCast(GridViewMBOFuncObjDetalis.Rows(e.RowIndex).FindControl("txtweight_fact0"), TextBox).Text
.................................
...........................
.....................
End If
if u want javascript msg alert try this ,just paste this javascript in html page inside Script tag.I think in sum u get total of weighting factor,if not pls try to get total of weighting factor in sum
function testmsg3(msg) {
alert(msg);
return false;
}
and in below pls see in checking place (exceeds 1 or not)
Protected Sub UpdateFuncObjDetails(ByVal sender As Object, ByVal e As GridViewUpdateEventArgs)
lblwtFactTotalmsg.Visible = False
Dim Conn As New SqlConnection(strConnString)
Dim sum As Double = 0.0
Dim str1 As String = String.Empty
Dim Comm1 As New SqlCommand
str1 = "select ISNULL(sum(MBO_Weighting_Factor),0) from tbl_MBO_Objective_Details where MBO_Req_Id is null and MBO_EMP_CODE='" & EMP_NO & "'"
Comm1 = New SqlCommand(str1, Conn)
Conn.Open()
sum = Comm1.ExecuteScalar()
Conn.Close()
if (sum >1) Then
ScriptManager.RegisterStartupScript(Me.Page, Me.[GetType](), "Alert", "<script type='text/javascript'>testmsg3('Your weghting factor total exceeds you can not
update the record !');</script>", False)
Else
Dim LblID As Integer = DirectCast(GridViewMBOFuncObjDetalis.Rows(e.RowIndex).FindControl("lblEditID"), Label).Text
Dim txtfuncobj As String = DirectCast(GridViewMBOFuncObjDetalis.Rows(e.RowIndex).FindControl("txtfuncobj0"), TextBox).Text
Dim txtmeasuredvar As String = DirectCast(GridViewMBOFuncObjDetalis.Rows(e.RowIndex).FindControl("txtmeasuredvar0"), TextBox).Text
Dim txtdeadline As String = DirectCast(GridViewMBOFuncObjDetalis.Rows(e.RowIndex).FindControl("txtdeadline0"), TextBox).Text
Dim txtweight_fact As String = DirectCast(GridViewMBOFuncObjDetalis.Rows(e.RowIndex).FindControl("txtweight_fact0"), TextBox).Text
Dim con As New SqlConnection(strConnString)
Dim cmd As New SqlCommand()
cmd.CommandType = CommandType.Text
cmd.CommandText = "update tbl_MBO_Objective_Details set MBO_Objective=@func_obj,MBO_Measured_Var=@mesrd_var,MBO_Target_Date=@tar_dt,MBO_Weighting_Factor=@wt_fact where id=@idnum;" & _
" select id, MBO_Objective,MBO_Measured_Var,MBO_Target_Date,MBO_Weighting_Factor from tbl_MBO_Objective_Details where MBO_Req_Id is null and MBO_Obj_Type_Id=1 and MBO_EMP_CODE='" & (EMP_NO) & "'"
cmd.Parameters.Add("@idnum", SqlDbType.VarChar).Value = LblID
cmd.Parameters.Add("@func_obj", SqlDbType.VarChar).Value = txtfuncobj
cmd.Parameters.Add("@mesrd_var", SqlDbType.VarChar).Value = txtmeasuredvar
cmd.Parameters.Add("@tar_dt", SqlDbType.VarChar).Value = txtdeadline
cmd.Parameters.Add("@wt_fact", SqlDbType.VarChar).Value = txtweight_fact
GridViewMBOFuncObjDetalis.EditIndex = -1
GridViewMBOFuncObjDetalis.DataSource = GetDataMBOFuncObjDetails(cmd)
GridViewMBOFuncObjDetalis.DataBind()
BindDataMBOPerObjectives()
End If
End Sub