For Each Item in radgrid

2 posts, 0 answers
  1. David Gunderson
    David Gunderson avatar
    13 posts
    Member since:
    Apr 2010

    Posted 02 May 2011 Link to this post

    I am tring to rotate through my radgrid to get the information  to save. The insert works fine becuase I can response.write my sql statement and it goes in fine.  I gets through one rotation and then seems to break the second time around.  I don't get it, it seems to work but does not work.

    Here is my Ragrid.
     <td><telerik:RadGrid ID="myGridDental" runat="server" Width="100%" BorderWidth="1px" CellPadding="6" GridLines="None" BorderColor="#404040">
                                                                <MasterTableView AutoGenerateColumns="false" DataKeyNames="intQuestionId" HierarchyDefaultExpanded="false" HierarchyLoadMode="ServerBind"
                                                                    BorderColor="#404040" Font-Size="12" Font-Names="Veranda,arial,sans-serif" HeaderStyle-HorizontalAlign="Center"
                                                                    GridLines="Both" BorderWidth="1px" ExpandCollapseColumn-ButtonType="ImageButton" ExpandCollapseColumn-CollapseImageUrl="~/Images/30.png"
                                                                    ExpandCollapseColumn-ExpandImageUrl="~/Images/29.png">
                                                                    <AlternatingItemStyle BackColor="#B0C4DE" />
                                                                    <HeaderStyle ForeColor="White" CssClass="backColor" BackColor="Steelblue" Font-Bold="true" BorderColor="#404040" BorderWidth="1px" />
                                                                    <Columns>
                                                                        <telerik:GridBoundColumn DataField="strQuestion" HeaderText="Question" />
                                                                        <telerik:GridTemplateColumn HeaderText="Help">
                                                                             <ItemTemplate>
                                                                                <asp:HyperLink ID="hylAttach" runat="server" ImageUrl="~/Images/paperclip.png" NavigateUrl='<%# bind("strUrl") %>' Target="_blank"
                                                                                Visible='<%# Not String.IsNullOrEmpty(Eval("strUrl")) %>' />
                                                                             </ItemTemplate>
                                                                        </telerik:GridTemplateColumn>
                                                                        <telerik:GridTemplateColumn HeaderText="GO\NOGO">
                                                                            <ItemTemplate>
                                                                                <asp:RadioButtonList ID="rblDental" runat="server" RepeatDirection="Horizontal" CellPadding="5" CellSpacing="5" TextAlign="Right">
                                                                                    <asp:ListItem Value="0" Text="GO" />
                                                                                    <asp:ListItem Value="1" Text="NO\GO" />
                                                                                </asp:RadioButtonList>
                                                                                <asp:RequiredFieldValidator ID="valDRadio" runat="server" ControlToValidate="rblDental" ErrorMessage="Not Answered" ForeColor="Red" ValidationGroup="Dental" />
                                                                            </ItemTemplate>
                                                                        </telerik:GridTemplateColumn>
                                                                        <telerik:GridTemplateColumn HeaderText="Data">
                                                                            <ItemTemplate>
                                                                                <asp:TextBox ID="txtData" runat="server" Width="60" />
                                                                            </ItemTemplate>
                                                                        </telerik:GridTemplateColumn>
                                                                        <telerik:GridTemplateColumn HeaderText="Remarks">
                                                                            <ItemTemplate>
                                                                                <asp:TextBox ID="txtRemarks" runat="server" Width="200" />
                                                                            </ItemTemplate>
                                                                        </telerik:GridTemplateColumn>
                                                                        <telerik:GridTemplateColumn HeaderText="Record Date">
                                                                            <ItemTemplate>
                                                                                <asp:TextBox ID="txtCal" runat="server" Width="100" style="cursor:pointer" />
                                                                                <asp:CalendarExtender ID="txtCal_CalendarExtender" runat="server" TargetControlID="txtCal" />
                                                                            </ItemTemplate>
                                                                        </telerik:GridTemplateColumn>
                                                                    </Columns>
                                                                    <DetailTables>
                                                                        <telerik:GridTableView Name="mySubDental" runat="server" DataKeyNames="intQuestionId" TableLayout="Fixed" BorderWidth="1px" CellPadding="6" Font-Size="12" AutoGenerateColumns="False"
                                                                            HeaderStyle-HorizontalAlign="Center" BorderColor="#404040" Font-Names="Veranda,arial,sans-serif" GridLines="Both">
                                                                            <ParentTableRelation>
                                                                                <telerik:GridRelationFields DetailKeyField="intQuestionId" MasterKeyField="intQuestionId" />
                                                                            </ParentTableRelation>
                                                                            <HeaderStyle ForeColor="White" BackColor="SteelBlue" Font-Bold="true" HorizontalAlign="Center" />
                                                                            <Columns>
                                                                                <telerik:GridBoundColumn DataField="strTaskName" HeaderText="Task" />
                                                                                <telerik:GridBoundColumn DataField="dtFound" HeaderText="Date" />
                                                                                <telerik:GridBoundColumn DataField="strNotes" HeaderText="Remarks" />
                                                                            </Columns>
                                                                        </telerik:GridTableView>
                                                                    </DetailTables>
                                                                </MasterTableView>
                                                            </telerik:RadGrid></td>
                                                        </tr>
                                                         <tr>
                                                            <td><asp:LinkButton ID="lnkSubmitDental" runat="server" ValidationGroup="Dental">Submit</asp:LinkButton></td>
                                                        </tr>
                                                    </table>

    Here is my code behind, it gets through one loop and then breaks and give me this error.

    Object reference not set to an instance of an object.   and then point to my sql statement.

     Protected Sub lnkSubmitDental_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkSubmitDental.Click
            Dim userlogon As String = Split(Current.User.Identity.Name, "\")(1)
            Dim lblErrorMsg As Label = DirectCast(Me.Master.FindControl("lblErrorMsg"), Label)
            Dim aError As HtmlAnchor = DirectCast(Me.Master.FindControl("aError"), HtmlAnchor)
            Dim lblError As Label = DirectCast(Me.Master.FindControl("lblError"), Label)
            Dim PersId As String = HFID.Value
            Dim AttendId As String = HFAttendID.Value

            For Each item As GridDataItem In myGridDental.Items
                Dim QuesId As Integer = myGridDental.Items(item.ItemIndex).GetDataKeyValue("intQuestionId")
                Dim data As TextBox = (TryCast(item.FindControl("txtData"), TextBox))
                Dim Remarks As TextBox = TryCast(item.FindControl("txtRemarks"), TextBox)
                Dim Dtdate As TextBox = TryCast(item.FindControl("txtCal"), TextBox)
                Dim answer As RadioButtonList = TryCast(item.FindControl("rblDental"), RadioButtonList)

                sql = "Insert tblSRpEventData (intPersonnelId, intSRPAttendId, intQuestionId, intAnswer, strData, strRemarks, strDocDate, dtLogged, strlogged) VALUES ('" & PersId & "',  " & AttendId & ", " _
                    & "" & QuesId & ", " & answer.SelectedValue & " , '" & Replace(data.Text, "'", "") & "', '" & Replace(Remarks.Text, "'", "") & "', '" & Replace(Dtdate.Text, "'", "") & "', '" & Date.Today & "', " _
                    & "'" & userlogon & "')"
               
                Try
                    insertUpdateDelete(sql)
                Catch ex As Exception
                    lblError.Text = ex.Message.ToString & " - ERROR Save Dental   <br> " & lblErrorMsg.Text
                    SetFocus(aError)
                End Try
            Next

        End Sub

  2. Iana Tsolova
    Admin
    Iana Tsolova avatar
    3388 posts

    Posted 04 May 2011 Link to this post

    Hello David,

    Can you specify at which line is the error thrown?
    I suggest that you refer to this help article for more information on how to implement batch updates with RadGrid:
    http://www.telerik.com/help/aspnet-ajax/grid-performing-batch-updates.html

    Regards,
    Iana
    the Telerik team

    Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top