locked
Setting <asp:Gridview multiple rows to Edit using EditIndex RRS feed

  • Question

  • User-159752495 posted

    Hello

    I have <asp:GridView on my page. I want to set multiple rows to edit mode and display respective file uploads in EditItemTemplate. I am checking from the database value and on the basis of this value , I am setting the EditIndex value of the Grid in Loop, but it is setting only single row to edit. How can I set multiple rows to Edit based on database values.

    Thanks

    Anoop Mathur

    Tuesday, February 12, 2019 9:27 AM

Answers

  • User61956409 posted

    Hi Anoop,

    There are multiple rows (suppose 6 rows) with file upload for each row. Now after checking the Status from the database, if the status is 1 for 4 rows out of 6 rows , then file upload must be available for those 4 rows and for remaining 2 rows, file upload must not be visible.

    To achieve the requirement, you can refer to the following code snippet.

    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false">
        <Columns>
            <asp:BoundField DataField="ID" HeaderText="ID" />
            <asp:TemplateField>
                <ItemTemplate>
                    <asp:Label ID="lblfile" runat="server" Text='<%#Eval("FileName") %>' Visible='<%# Eval("Status").ToString() != "1" ? true : false %>'></asp:Label>
                    <asp:FileUpload ID="fupload" runat="server" Visible='<%# Eval("Status").ToString() == "1" ? true : false %>' />
                </ItemTemplate>
            </asp:TemplateField>
            <asp:BoundField DataField="Status" HeaderText="Status" />
        </Columns>
    </asp:GridView>

    Test Result:

    With Regards,

    Fei Han

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, February 13, 2019 3:39 AM

All replies

  • User-1716253493 posted

    GridView only has single row edit, if you want multiple row edit place input control in itemtemplate, based value from db you can make it readonly or invisible.

    To save all, loop the grid rows

    Tuesday, February 12, 2019 10:25 AM
  • User-159752495 posted

    Hello,

              I have File Upload in EditItemTemplate. How can I then edit multiple rows

    Thanks

    Anoop Mathur

    Tuesday, February 12, 2019 10:39 AM
  • User-2054057000 posted

    I explain you this further. Suppose your GridView has 5 rows then when opting in for edit row feature. Then you will have 5 editable rows and these rows can only be edited one at a time. 

    May be you want to explain your full scenario to us?

    I would ask you to put your full codes of both .aspx and .cs pages and explain what are you trying to achieve.

    Tuesday, February 12, 2019 11:02 AM
  • User-159752495 posted

    Hello,

              There are multiple rows (suppose 6 rows) with file upload for each row. Now after checking the Status from the database, if the status is 1 for 4 rows out of 6 rows , then file upload must be available for those 4 rows and for remaining 2 rows, file upload must not be visible.

    Thank You

    Anoop Mathur

    Tuesday, February 12, 2019 11:08 AM
  • User61956409 posted

    Hi Anoop,

    There are multiple rows (suppose 6 rows) with file upload for each row. Now after checking the Status from the database, if the status is 1 for 4 rows out of 6 rows , then file upload must be available for those 4 rows and for remaining 2 rows, file upload must not be visible.

    To achieve the requirement, you can refer to the following code snippet.

    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false">
        <Columns>
            <asp:BoundField DataField="ID" HeaderText="ID" />
            <asp:TemplateField>
                <ItemTemplate>
                    <asp:Label ID="lblfile" runat="server" Text='<%#Eval("FileName") %>' Visible='<%# Eval("Status").ToString() != "1" ? true : false %>'></asp:Label>
                    <asp:FileUpload ID="fupload" runat="server" Visible='<%# Eval("Status").ToString() == "1" ? true : false %>' />
                </ItemTemplate>
            </asp:TemplateField>
            <asp:BoundField DataField="Status" HeaderText="Status" />
        </Columns>
    </asp:GridView>

    Test Result:

    With Regards,

    Fei Han

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, February 13, 2019 3:39 AM