locked
not able to get NewEditIndex for gridview inside repeater RRS feed

  • Question

  • User646364117 posted

    I am trying to edit data of a gridview inside a repeater. When I click the edit button and debug, I am getting a null refernce error for gv.EditIndex

        Protected Sub gvContent_RowEditing(sender As Object, ByVal e As System.Web.UI.WebControls.GridViewEditEventArgs)
            Dim gv As GridView = CType(sender.FindControl("gvContent"), GridView)
            gv.EditIndex = e.NewEditIndex
            BindRepeater()
        End Sub
                <asp:Repeater ID="rptBlock" runat="server">
                    <ItemTemplate>
    
                        <asp:Label ID="Label1" runat="server" Text="Block: " Style="font-weight: bold; color: black; background-color: #5DBCD2;" />
                        <asp:Label ID="lblBlock" runat="server" Text='<%# Eval("name") %>' Style="font-weight: bold; color: black; background-color: #5DBCD2; padding-left: 3px; padding-right: 3px;" />
                        <asp:Literal ID="Literal2" runat="server"> is assigned to these templates: </asp:Literal>
                        <asp:HiddenField ID="hfBlockID" runat="server" Value='<%# Eval("id") %>'></asp:HiddenField>
                        <asp:HiddenField ID="hfBlockType" runat="server" Value='<%# Eval("blocktype") %>'></asp:HiddenField>
                        <asp:TextBox ID="txtTemplateList" runat="server" Text='<%# Eval("TemplateList") %>' Visible="True" Style="font-weight: bold;" TextMode="MultiLine" />
                        <asp:ImageButton ID="btnAssignTemplates" runat="server" src="images/addnew_21.png" CommandName="AssignTemplates" />
    
    
                        <asp:Panel ID="Panel1" runat="server">
                            <h3>Assign Block To Templates</h3>
                            <asp:ListBox ID="lstTemplate" Width="250" SelectionMode="Multiple" runat="server"></asp:ListBox>
                            <asp:HiddenField ID="txtTemplateIDList" runat="server" Value='<%# Eval("templateidList") %>'></asp:HiddenField>
                            <asp:HiddenField ID="blockID" runat="server" Value='<%# Eval("id") %>'></asp:HiddenField>
                            <asp:ImageButton ID="btnSaveAssignedTemplates" runat="server" src="images/save_20.png" CommandName="SaveTemplates" />
                            <asp:ImageButton ID="btnCancelAssignTemplates" runat="server" src="images/cancel_20.png" CommandName="CancelAssignTemplates" />
                        </asp:Panel>
                        <asp:GridView ID="gvContent"
                            AutoGenerateColumns="false"
                            runat="server"
                            OnRowEditing="gvContent_RowEditing"
                            OnRowUpdating="gvContent_RowUpdating"
                            OnRowCancelingEdit="gvContent_RowCancelingEdit"
                            OnRowDataBound="gvContent_OnRowDataBound">
    
    
                            <Columns>
                                <asp:BoundField DataField="shorttext" HeaderText="Short Text" ItemStyle-Width="300" />
                                <asp:BoundField DataField="longtext" HeaderText="Long Text" ItemStyle-Width="300" />
                                <asp:CommandField ShowEditButton="true" ButtonType="Image" EditImageUrl="~/images/edit_20.png"
                                    UpdateImageUrl="~/images/save_20.png" DeleteImageUrl="~/images/delete_20.png"
                                    HeaderText="Edit" />
    
                            </Columns>
    
    
    
                        </asp:GridView>
    
                    </ItemTemplate>
                    <SeparatorTemplate>
                        <br />
                        <hr />
                        <br />
                    </SeparatorTemplate>
                </asp:Repeater>

    Sunday, February 9, 2020 3:01 PM

Answers

  • User646364117 posted

    Found solution

    Dim gv As GridView = CType(sender, GridView)
        gv.EditIndex = e.NewEditIndex



    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Sunday, February 9, 2020 3:25 PM