Click here to Skip to main content
15,917,928 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to add the girdview controls one perticular column and want to check wheather the total exceeds 1 or not if total exceeds 1 then user should not be allowed to add another row to gridview else if total does not exceeds 1 then user allowed to add new row dynamically.
Here is the code
If ViewState("CurrentTable") IsNot Nothing Then
           Dim dtCurrentTable As DataTable = DirectCast(ViewState("CurrentTable"), DataTable)
           Dim drCurrentRow As DataRow = Nothing
           If dtCurrentTable.Rows.Count > 0 Then
               For i As Integer = 1 To dtCurrentTable.Rows.Count
                   Dim txtfunob As TextBox = DirectCast(grv_set_func_obj.Rows(rowIndex).Cells(1).FindControl("txtfuncobj"), TextBox)
                   Dim txtmeasur As TextBox = DirectCast(grv_set_func_obj.Rows(rowIndex).Cells(2).FindControl("txtmeasuredvar"), TextBox)
                   Dim txtd_line As TextBox = DirectCast(grv_set_func_obj.Rows(rowIndex).Cells(3).FindControl("txtdeadline"), TextBox)
                   Dim txtwtfact As TextBox = DirectCast(grv_set_func_obj.Rows(rowIndex).Cells(4).FindControl("txtweight_fact"), TextBox)
                   Dim temp As String = txtwtfact.Text.ToString
                   tot = tot + Convert.ToDouble(temp)
                   'count = count + 1
                   'MsgBox(count)
                   MsgBox(tot)
                   If tot = 1.0F Then
                       lbltot.Visible = True
                       lbltot.Text = " Your weighting factor becomes one.."
                   End If
                   If tot > 1.0F Then
                       lbltot.Visible = True
                       lbltot.Text = " Your weighting factor exceeds one.."
                   Else
                       lbltot.Visible = False
                   End If

                   drCurrentRow = dtCurrentTable.NewRow()
                   drCurrentRow("RowNumber") = i + 1

                   dtCurrentTable.Rows(i - 1)("Col1") = txtfunob.Text
                   dtCurrentTable.Rows(i - 1)("Col2") = txtmeasur.Text
                   dtCurrentTable.Rows(i - 1)("Col3") = txtd_line.Text
                   dtCurrentTable.Rows(i - 1)("Col4") = txtwtfact.Text

                   rowIndex += 1
               Next
               dtCurrentTable.Rows.Add(drCurrentRow)
               ViewState("CurrentTable") = dtCurrentTable

               grv_set_func_obj.DataSource = dtCurrentTable
               grv_set_func_obj.DataBind()

               Dim txtfnobj As TextBox = DirectCast(grv_set_func_obj.Rows(rowIndex).Cells(1).FindControl("txtfuncobj"), TextBox)
               txtfnobj.Focus()

           End If
Posted

1 solution

 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900