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"
                                                                    <AlternatingItemStyle BackColor="#B0C4DE" />
                                                                    <HeaderStyle ForeColor="White" CssClass="backColor" BackColor="Steelblue" Font-Bold="true" BorderColor="#404040" BorderWidth="1px" />
                                                                        <telerik:GridBoundColumn DataField="strQuestion" HeaderText="Question" />
                                                                        <telerik:GridTemplateColumn HeaderText="Help">
                                                                                <asp:HyperLink ID="hylAttach" runat="server" ImageUrl="~/Images/paperclip.png" NavigateUrl='<%# bind("strUrl") %>' Target="_blank"
                                                                                Visible='<%# Not String.IsNullOrEmpty(Eval("strUrl")) %>' />
                                                                        <telerik:GridTemplateColumn HeaderText="GO\NOGO">
                                                                                <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:RequiredFieldValidator ID="valDRadio" runat="server" ControlToValidate="rblDental" ErrorMessage="Not Answered" ForeColor="Red" ValidationGroup="Dental" />
                                                                        <telerik:GridTemplateColumn HeaderText="Data">
                                                                                <asp:TextBox ID="txtData" runat="server" Width="60" />
                                                                        <telerik:GridTemplateColumn HeaderText="Remarks">
                                                                                <asp:TextBox ID="txtRemarks" runat="server" Width="200" />
                                                                        <telerik:GridTemplateColumn HeaderText="Record Date">
                                                                                <asp:TextBox ID="txtCal" runat="server" Width="100" style="cursor:pointer" />
                                                                                <asp:CalendarExtender ID="txtCal_CalendarExtender" runat="server" TargetControlID="txtCal" />
                                                                        <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">
                                                                                <telerik:GridRelationFields DetailKeyField="intQuestionId" MasterKeyField="intQuestionId" />
                                                                            <HeaderStyle ForeColor="White" BackColor="SteelBlue" Font-Bold="true" HorizontalAlign="Center" />
                                                                                <telerik:GridBoundColumn DataField="strTaskName" HeaderText="Task" />
                                                                                <telerik:GridBoundColumn DataField="dtFound" HeaderText="Date" />
                                                                                <telerik:GridBoundColumn DataField="strNotes" HeaderText="Remarks" />
                                                            <td><asp:LinkButton ID="lnkSubmitDental" runat="server" ValidationGroup="Dental">Submit</asp:LinkButton></td>

    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 & "')"
                Catch ex As Exception
                    lblError.Text = ex.Message.ToString & " - ERROR Save Dental   <br> " & lblErrorMsg.Text
                End Try

        End Sub

  2. Iana Tsolova
    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:

    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.

Back to Top