Click here to Skip to main content
15,998,694 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Who will rid me of this troublesome nested Gridview...



I have two issues with the nested Gridview
1. I have to click the Edit Link twice to get it to fire
2. When it does fire the edit fields are blank instead of containing the text to be edited
the Delete and the ADD actions work without issue

Here is the aspx code for the nested gridview:
<%-- This grid holds all the child elements --%>
<asp:TemplateField>
  <ItemTemplate>
... <tr>
......<td colspan="100%">
...... <div id="div<%# Eval("BulletGroupID") %>" class="gv-bulletItems" >
.........  
.........  <asp:GridView ID="gvBulletItems" runat="server"
............ AllowPaging="True" AllowSorting="true" BackColor="White" Width="100%" Font-Size="X-Small"
............ AutoGenerateColumns="false" Font-Names="Verdana" DataKeyNames="BulletGroupID" ShowFooter="true"
............ BorderStyle="Double" BorderColor="#0083C1"
............ OnPageIndexChanging="gvBulletItems_OnPageIndexChanging" 
............ OnRowUpdating="gvBulletItems_OnRowUpdating"
............ OnRowCommand="gvBulletItems_OnRowCommand" 
............ OnRowEditing="gvBulletItems_OnRowEditing"
............ OnRowCancelingEdit="gvBulletItems_OnRowCancelingEdit"
............ OnRowDataBound="gvBulletItems_OnRowDataBound" 
............ OnRowDeleting="gvBulletItems_OnRowDeleting">
............ 
............ <RowStyle BackColor="LightCyan" />
............ <AlternatingRowStyle BackColor="White" />
............ <HeaderStyle BackColor="#0083C1" ForeColor="White" />
............ <FooterStyle BackColor="PaleTurquoise" />
............ <Columns>
...............<asp:TemplateField HeaderText="BulletGroup ID" Visible="False" SortExpression="BulletGroupID">
...............   <ItemTemplate>
..................  <asp:Label ID="lblBulletGroupID" Text='<%# Eval("BulletGroupID") %>' Visible="False" runat="server"></asp:Label>
...............   </ItemTemplate>

...............</asp:TemplateField>
...............<asp:TemplateField HeaderText="BulletGroup ID" Visible="False" SortExpression="BulletID">
...............   <ItemTemplate>
..................  <asp:Label ID="lblBulletID" Text='<%# Eval("BulletID") %>' Visible="False" runat="server"></asp:Label>
...............   </ItemTemplate>

...............</asp:TemplateField>
...............<asp:TemplateField HeaderText="List Order" SortExpression="ListOrder">
...............   <ItemTemplate><%# Eval("ListOrder")%>  </ItemTemplate>
...............   <EditItemTemplate>
..................  <asp:TextBox ID="txtBiListOrder" Text='<%# Eval("ListOrder")%>' runat="server"></asp:TextBox>
...............   </EditItemTemplate>
...............   <FooterTemplate>
..................  <asp:TextBox ID="txtBiListOrder" Text="" runat="server"></asp:TextBox>
...............   </FooterTemplate>
...............</asp:TemplateField>

...............<asp:TemplateField HeaderText="Bullet Text" SortExpression="DisplayText">
...............   <ItemTemplate><%# Eval("DisplayText")%></ItemTemplate>
...............   <EditItemTemplate>
..................  <asp:TextBox ID="txtBiDisplayText" Text='<%# Eval("DisplayText")%>'  runat="server"></asp:TextBox>
...............   </EditItemTemplate>
...............   <FooterTemplate>
..................  <asp:TextBox ID="txtBiDisplayText" Text="" runat="server"></asp:TextBox>
...............   </FooterTemplate>
...............</asp:TemplateField>
...............<asp:CommandField HeaderText="Edit" ShowEditButton="True" />
...............<asp:CommandField HeaderText="Delete" ShowDeleteButton="True"/>
...............<asp:TemplateField >
...............   <FooterTemplate>
..................  <asp:LinkButton ID="linkAddBulletItem" CommandName="AddBulletItem" runat="server">Add</asp:LinkButton>
...............   </FooterTemplate>
...............</asp:TemplateField>
............ </Columns>
.........  </asp:GridView>
...... </div>
......</td>
... </tr>
  </ItemTemplate>
</asp:TemplateField>


FYI the parent gridview does not have any of these issues

What I have tried:

Stepping through the code, side by side comparision of the parent gridview
Posted
Updated 18-Dec-18 11:38am
v2
Comments
[no name] 18-Dec-18 11:23am    
Check for postback on parent grid and make sure you have data binded to nested grid control when your click event fired. Seems nested grid getting cleared on postback

1 solution

Quote:
1. I have to click the Edit Link twice to get it to fire


If you are binding your GridView at Page_Load event, then make sure to wrap your code for binding within !IsPostback block:
C#
protected void Page_Load(object sender, EventArgs e)
{
        if (!Page.IsPostBack)
        {
            //Your code for binding your GridView here
        }
}


Quote:
2. When it does fire the edit fields are blank instead of containing the text to be edited
the Delete and the ADD actions work without issue


Make sure that you are repopulating your GridView at RowEditing right after you set the NewEditIndex. For example:
C#
protected void GridViewEmployee_RowEditing(object sender, GridViewEditEventArgs e)
{
    GridViewEmployee.EditIndex = e.NewEditIndex; // turn to edit mode
    // Rebind your GridView with the datasource here to show the data in edit mode

}
 
Share this answer
 
Comments
RmcbainTheThird 19-Dec-18 9:47am    
Well the rebinding works but I was never able to get a value that would allow me to identify the one gridview I was editing in and rebind that one. I ended up having to rebind ALL the nested gridviews. I am going to stick a fork in it and call it done

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900