Using
I have 2 GridViews nested one in another with radio button list controls. The first and second Grid view's Radio Button list have same buttons like Yes, No, N/A. When the parents "No" List item is clicked it should show the nested grid view and its associated radio buttons and let the user click on it. But when the No and N/A radiobuttons are clicked, the childs yes and N/A should get autoclicked and when the user deselects it should deselect parents yes and N/A.
When I hit the submit button, it should only take the child's radiobutton values and save it in database.
The code is below. Any help is appreciated.
$(function () {
$('[id*=QuestList]').click(function () {
var text = $(this).val();
if (text == "Yes") {
$(this).closest('table').parent().find('div').hide();
$(this).attr('checked', true);
}
else if (text == "No") {
$(this).closest('table').parent().find('div').toggle();
}
else if (text == "N/A") {
$(this).closest('table').parent().find('div').hide();
}
});
});
$(document).on('change', '[id*=QuestList]', function () {
$('[StandList="' + $(this).attr('QuestList') + '"]:first').prop('checked', true);
});
$(document).on('change', '[id*=QuestList]', function () {
$('[StandList="' + $(this).attr('QuestList') + '"]').prop('checked', true);
});
Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
If Not IsPostBack Then
GridView1.DataSource = GetData("select * from Questions")
GridView1.DataBind()
End If
End Sub
Protected Sub OnRowDataBound(sender As Object, e As GridViewRowEventArgs)
If e.Row.RowType = DataControlRowType.DataRow Then
Dim questid As String = GridView1.DataKeys(e.Row.RowIndex).Value.ToString()
Dim GridView2 As GridView = TryCast(e.Row.FindControl("GridView2"), GridView)
GridView2.DataSource = GetData(String.Format("SELECT * from Standards where Questions= '{0}'", questid))
GridView2.DataBind()
End If
End Sub
Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim strConnString As String = ConfigurationManager.ConnectionStrings("ConnectionString2").ConnectionString
Dim strSQL As String = String.Empty
Dim cn As SqlConnection = New SqlConnection(strConnString)
cn.Open()
Dim strResponse As String = String.Empty
For Each row As GridViewRow In GridView1.Rows
Dim btn1 As RadioButtonList = CType(GridView1.Rows(row.RowIndex).FindControl("QuestList"), RadioButtonList)
Dim gview As GridView = CType(GridView1.Rows(row.RowIndex).FindControl("GridView2"), GridView)
Dim btn2 As RadioButtonList = CType(gview.Rows(row.RowIndex).FindControl("StandList"), RadioButtonList)
If btn1.SelectedItem.Text = "Yes" Then
btn2.SelectedValue = "Yes"
ElseIf btn1.SelectedItem.Text = "N/A" Then
btn2.SelectedValue = "N/A"
End If
If btn2.SelectedValue = "Yes" Then
strResponse = "Yes"
ElseIf btn2.SelectedValue = "No" Then
strResponse = "No"
ElseIf btn2.SelectedValue = "N/A" Then
strResponse = "N/A"
End If
Next
strSQL = "Update Results set Response = '" & strResponse & "' where Standard = '"
Dim cmd As SqlCommand = New SqlCommand(strSQL, cn)
cmd.ExecuteNonQuery()
cn.Close()
End Sub