Andy Green
asked on
Gridview GridViewRow is empty
Hi Experts
I have a Gridview with a template Col with a check box, what I want to to (and Am doing sucsesssfully with a test page and I GV) is detect which rows have a tick on post back.
My page has 3 GV's each with a unique ID, when I tick any of the boxes and hit a go btn the GridViewRow is empty. I have a test page with 1 GV and it works OK, so the problem appears to be around the multi GV's I can post my code if required, but it does work.
Has anyone seen this behaviour before and found a solution, or is it me?
Andy
I have a Gridview with a template Col with a check box, what I want to to (and Am doing sucsesssfully with a test page and I GV) is detect which rows have a tick on post back.
My page has 3 GV's each with a unique ID, when I tick any of the boxes and hit a go btn the GridViewRow is empty. I have a test page with 1 GV and it works OK, so the problem appears to be around the multi GV's I can post my code if required, but it does work.
Has anyone seen this behaviour before and found a solution, or is it me?
Andy
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
If Possible post your code , so that its easy to understand the problem
ASKER
Hi
Re bound the data and whilst GridViewRows now have data, the selected rows have been cleared.
What I dont understand is the code works fine with 1 GV but not multiple.
The code pages are quite large, but this is my template section and code behind for the working one, which is identical to the faulty one. I think I'm loosing data on postback some where but cant find it. If all else fails I can capture the clicks on the client and persist those.
<asp:TemplateField>
<ItemTemplate>
<asp:CheckBox ID="selectQuestion" runat="server" />
</ItemTemplate>
</asp:TemplateField>
Protected Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
For Each row As GridViewRow In gvAvailableQuestions.Rows
Dim cb As CheckBox = row.FindControl("selectQue stion")
If cb IsNot Nothing AndAlso cb.Checked Then
Dim QuestionID As Integer = _
Convert.ToInt32(gvAvailabl eQuestions .DataKeys( row.RowInd ex).Value)
lbldebug.Text &= String.Format("You Selected {0}<br />", QuestionID)
End If
Next
End Sub
Re bound the data and whilst GridViewRows now have data, the selected rows have been cleared.
What I dont understand is the code works fine with 1 GV but not multiple.
The code pages are quite large, but this is my template section and code behind for the working one, which is identical to the faulty one. I think I'm loosing data on postback some where but cant find it. If all else fails I can capture the clicks on the client and persist those.
<asp:TemplateField>
<ItemTemplate>
<asp:CheckBox ID="selectQuestion" runat="server" />
</ItemTemplate>
</asp:TemplateField>
Protected Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
For Each row As GridViewRow In gvAvailableQuestions.Rows
Dim cb As CheckBox = row.FindControl("selectQue
If cb IsNot Nothing AndAlso cb.Checked Then
Dim QuestionID As Integer = _
Convert.ToInt32(gvAvailabl
lbldebug.Text &= String.Format("You Selected {0}<br />", QuestionID)
End If
Next
End Sub
ASKER
Andy