I am developing an ASP.NET application for a business. I am working on an 'audit' page and i am populating an HTML table, i am getting the results from and SQL Server and writing a table row for each row in the SQL Query Result
Here is the table code
<table style="width:100%; text-align:center">
<tr>
<td><b><u>Question</u></b></td>
<td><b><u>Pass</u></b></td>
<td><b><u>Fail</u></b></td>
</tr>
<% If AuditQuestions Is Nothing Then %>
<tr>
<td colspan="3">The Audit Questions Have Not Been Specified In The Database</td>
</tr>
<% Else If AuditQuestions.Rows.Count = 0 Then %>
<tr>
<td colspan="3">The Audit Questions Have Not Been Specified In The Database</td>
</tr>
<% Else
For i As Integer = 0 To (AuditQuestions.Rows.Count - 1)
If i > 20 Then
Exit For
End If
With AuditQuestions.Rows.Item(i) %>
<tr>
<td><% Response.Write(.Item("Question")) %></td>
<td>
<input type="submit" style="background-color: green; width: 100%" onclick="<% SubmitAuditQuestion(.Item("Question"), "Pass", DDCC.SelectedValue) %>" Value="Pass"/>
</td>
<td>
<input type="button" style="background-color: red; width: 100%" onclick="" Value="Fail"/>
</td>
</tr>
<% End With
Next
End If
%>
</table>
But i am having trouble with the button onclick
<input type="submit" style="background-color: green; width: 100%" onclick="<% SubmitAuditQuestion(.Item("Question"), "Pass", DDCC.SelectedValue) %>" Value="Pass"/>
I want it to execute this code when the button is clicked in the vb file
Public Sub SubmitAuditQuestion(Question As String, Result As String, DrillPath As String)
Dim con As New SqlConnection(CS)
Dim cmd As New SqlCommand("[dbo].[app_Audit_Question_Submit] @audittype = '" & audittype & "', @auditby = '" & My.User.Name & "', @auditbyid = '" & _Default.EntityID & "', @auditdate = '" & Date.Today & "', @employeename = '" & If(audittype = "5S", DDStaff.SelectedValue, vbNull) & "', @auditmbu = '" & DDCC.SelectedValue & "', @question = '" & Question & "', @result = '" & Result & "', @drillpath = '" & DrillPath & "', @timestamp = '" & Now & "' ", con)
con.Open()
cmd.ExecuteNonQuery()
con.Close()
but that code is executing when the page loads for each row, and when i click on one of the buttons, it executes for the the table rows
Please Help.
Thanks,