Ok,
when I am adding a new row to the nested gridview(gvBulletItems) and there are existing rows I can get parent ID with
gvBulletItems.DataKeys[0].Value
(BTW I hate magic numbers)
however when I a have parent gridview with no Items in the nested gridview DataKeys comes back as null
I have defined my EmptyDataTemplate thusly:
<EmptyDataTemplate>
There are no Bullets for this bullet group.
<table id="tblnewbullets" class="tbl-newItems" runat="server">
<tr class="tbl-newItems">
<td class="tbl-newItems" > List Order</td>
<td> Display Text</td>
</tr>
<tr>
<td>
<asp:TextBox ID="txtbxNewListOrder" runat="server"></asp:TextBox>
</td>
<td>
<asp:TextBox ID="txtbxNewDisplayText" runat="server"></asp:TextBox>
</td>
<td>
<asp:LinkButton ID="linkAddBullet" CommandName="AddNewBullet" runat="server">Add</asp:LinkButton>
</td>
</tr>
</table>
</EmptyDataTemplate>
and this defined before
<Columns>
.....
</Columns>
One of the things I thought of was that I could it from is the ID of the div that the nested gridview as its ID is defined as
"div<%# Eval("BulletGroupID") %>"
but when I look that is not the ID.
here is the code that binds both gridviews
if (row.RowType == DataControlRowType.DataRow)
{
InfoCenterParent icParent = (InfoCenterParent)Session[PARENT];
List<InfoCenterBulletGroup> bulletGroupsData = icParent.bulletGroups;
Label lblGroupBulletID = (Label)row.FindControl("lblBulletGroupID");
int BulletGroupID = int.Parse(lblGroupBulletID.Text);
InfoCenterBulletGroup bg = bulletGroupsData.Single(b => b.BulletGroupID == BulletGroupID);
GridView gvBulletItems = new GridView();
gvBulletItems = (GridView)row.FindControl("gvBulletItems");
gvBulletItems.DataSource = bg.bulletItems;
gvBulletItems.DataBind();
}
and here is how I am retrieving the BulletgroupID in the OnRowCommand of the nested gridview
gvBulletItems.DataKeys[0].Value.ToString()
this object(gvBulletItems.DataKeys) is not null if I am added a bulletitem to a gridview that has existing items
however if I am adding to a the nested gridview that has no items then it comeback as null
Here is the object that gets bound to the gridviews
public class InfoCenterBulletGroup
{
public int BulletGroupID { get; set; }
public int InfoCenterID { get; set; }
public string DisplayText { get; set; }
public int ListOrder { get; set; }
public List<InfoCenterBulletItem> bulletItems { get; set; }
public string LastUpdatedBy { get; set; }
public DateTime LastUpdatedDate { get; set; }
}
public class InfoCenterBulletItem
{
public int BulletID { get; set; }
public int BulletGroupID { get; set; }
public int ListOrder { get; set; }
public string DisplayText { get; set; }
public string LastUpdatedBy { get; set; }
public DateTime LastUpdatedDate { get; set; }
}
What I have tried:
I have tried assigning
<%# Eval("BulletGroupID") %>"
to label text in my emptyDataTemplate
I have dug through all the properties of both gridviews
I have worn out my keyboard with Google searches