User-939850651 posted
Hi inkaln,
According to the limited code you provided, I am not sure whether your problem is completely reproduced. If my guess is correct, you can try to get the index of the ListViewItem and then get the LVId.
This is my test:
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
DataTable LVData = new DataTable();
LVData.Columns.Add("LVId");
LVData.Rows.Add(1);
LVData.Rows.Add(2);
lvGrids.DataSource = LVData;
lvGrids.DataBind();
}
}
protected void lvGrids_ItemDataBound(object sender, ListViewItemEventArgs e)
{
if (e.Item.ItemType == ListViewItemType.DataItem)
{
GridView grid = e.Item.FindControl("gvChildGrid") as GridView;
DataTable GVData = new DataTable();
GVData.Columns.Add("GVId");
GVData.Columns.Add("Col1");
GVData.Columns.Add("Col2");
GVData.Rows.Add(1, "Col11", "Col21");
GVData.Rows.Add(2, "Col12", "Col22");
GVData.Rows.Add(3, "Col13", "Col23");
grid.DataSource = GVData;
grid.DataBind();
}
}
protected void gvChildGrid_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
ListViewItem item = e.Row.Parent.Parent.Parent as ListViewItem;
string dataKey = lvGrids.DataKeys[item.DataItemIndex][0].ToString();
}
}
<asp:ListView ID="lvGrids" runat="server" DataKeyNames="LVId" OnItemDataBound="lvGrids_ItemDataBound">
<ItemTemplate>
<asp:GridView runat="server" ID="gvChildGrid" DataKeyNames="GVId" OnRowDataBound="gvChildGrid_RowDataBound"></asp:GridView>
</ItemTemplate>
</asp:ListView>
If I misunderstood something, please post the complete code, which will help us solve the problem.
Best regards,
Xudong Peng