Dear Friends,
How do we get the cell value of nested grid view when we click image button in the nested grid view.
Also we want to get the value of parent gridview cell value when we click imagebutton inside child gridview.
Code is enclosed for your reference.
<div class="main">
<asp:GridView ID="RptSearch_Gridview" runat="server" AutoGenerateColumns="false"
BorderColor="black" BorderWidth="1" CellPadding="3" Width="96%" GridLines="both"
OnSelectedIndexChanged="OnSelectedIndexChanged" OnRowCreated="GridView_Products_RowCreated"
OnRowCommand="Grid_downbtnClick" OnRowDataBound="OnRowDataBound">
<RowStyle BackColor="Silver" />
<SelectedRowStyle BackColor="yellow" ForeColor="black" Font-Bold="true" />
<AlternatingRowStyle BackColor="lavender" />
<RowStyle BackColor="White" ForeColor="Black" />
<HeaderStyle BackColor="darkslateblue" ForeColor="White" />
<FooterStyle BackColor="lightgray" ForeColor="black" />
<PagerStyle ForeColor="#8C4510" HorizontalAlign="Center"></PagerStyle>
<Columns>
<asp:TemplateField HeaderText="S.NO" ItemStyle-Width="30">
<ItemTemplate>
<asp:Label ID="lblRowNumber" Text='<%# Container.DataItemIndex + 1 %>' runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField ItemStyle-Width="15">
<ItemTemplate>
<!-- <img alt = "" style="cursor: pointer" src="images/plus.png" />-->
<asp:ImageButton ID="imgProductsShow" runat="server" OnClick="Show_Hide_OrdersGrid"
ImageUrl="~/images/plus.png" CommandArgument="Show" />
<asp:Panel ID="pnlOrders" runat="server" Style="display: none">
<asp:GridView ID="NestedGridView" runat="server" AutoGenerateColumns="false" ShowFooter="true"
OnRowCommand="NestedGridView_RowCommand" OnRowCreated="NestedGridView_RowCreated">
<HeaderStyle BackColor="#FF00FF" ForeColor="White" />
<AlternatingRowStyle BackColor="#D3D3D3" />
<FooterStyle BackColor="#cccccc" Font-Bold="True" ForeColor="Black" HorizontalAlign="Left" />
<Columns>
<asp:TemplateField>
<ItemTemplate>
<center>
<asp:ImageButton ID="childDwnimgBtn" runat="server" Style="width: 15px; height: 15px;"
ImageUrl="Images\dwn_img.jpg" CommandName="SupDocDownload" ToolTip="Supplier document download"
CommandArgument='<%#Container.DataItemIndex%>' /></center>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField ItemStyle-Width="50px" DataField="enq_num" HeaderText="Enq.No" />
<asp:BoundField ItemStyle-Width="30px" DataField="vdr_code" HeaderText="VCode" />
<asp:BoundField ItemStyle-Width="300px" DataField="vcom_name" HeaderText="Vendor Name" />
<asp:BoundField ItemStyle-Width="25px" DataField="qty" HeaderText="Qty" />
<asp:BoundField ItemStyle-Width="80px" DataField="quote_price" HeaderText="Qtd.Price/Unit" />
<asp:BoundField ItemStyle-Width="50px" DataField="Total" HeaderText="Total" />
<asp:BoundField ItemStyle-Width="100px" DataField="del_dt" HeaderText="Delivery"
DataFormatString="{0:dd-MM-yyyy}" />
<asp:TemplateField>
<FooterTemplate>
<asp:Button ID="Button1" CommandName="GetComparative" Text="Comp.Chart" runat="server" />
</FooterTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</asp:Panel>
</ItemTemplate>
</asp:TemplateField>
<asp:HyperLinkField DataTextField="enq_num" DataNavigateUrlFields="enq_num" DataNavigateUrlFormatString="Enq_Details.aspx?id={0}"
Target="_blank" ItemStyle-Width="30" HeaderText="EQ.NO" />
<asp:BoundField ReadOnly="True" HeaderText="JOB NUM" InsertVisible="False" DataField="job"
ItemStyle-Width="65" SortExpression="ProductID">
<ItemStyle HorizontalAlign="Center"></ItemStyle>
</asp:BoundField>
<asp:BoundField ReadOnly="True" HeaderText="POS" InsertVisible="False" DataField="pos"
ItemStyle-Width="55" SortExpression="Productpos">
<ItemStyle HorizontalAlign="Center"></ItemStyle>
</asp:BoundField>
<asp:BoundField ReadOnly="True" HeaderText="ITEM" InsertVisible="False" DataField="item"
SortExpression="Productitem">
<ItemStyle HorizontalAlign="Center"></ItemStyle>
</asp:BoundField>
<asp:BoundField ReadOnly="True" HeaderText="QTY" InsertVisible="False" DataField="qty"
SortExpression="Productqty">
<ItemStyle HorizontalAlign="Center"></ItemStyle>
</asp:BoundField>
<asp:BoundField ReadOnly="True" HeaderText="BUDGET" InsertVisible="False" DataField="Budget"
SortExpression="Productqty">
<ItemStyle HorizontalAlign="Center"></ItemStyle>
</asp:BoundField>
<asp:BoundField ReadOnly="True" HeaderText="CDD" InsertVisible="False" DataField="cdd"
ItemStyle-Width="80" DataFormatString="{0:dd-MM-yyyy}" SortExpression="Proddt">
<ItemStyle HorizontalAlign="Center"></ItemStyle>
</asp:BoundField>
<asp:BoundField ReadOnly="True" HeaderText="RDD" InsertVisible="False" DataField="rdd"
ItemStyle-Width="80" DataFormatString="{0:dd-MM-yyyy}" SortExpression="Proddt">
<ItemStyle HorizontalAlign="Center"></ItemStyle>
</asp:BoundField>
<asp:BoundField ReadOnly="True" HeaderText="DUE DATE" InsertVisible="False" DataField="due_dt"
ItemStyle-Width="80" DataFormatString="{0:dd-MM-yyyy}" SortExpression="Proddt">
<ItemStyle HorizontalAlign="Center"></ItemStyle>
</asp:BoundField>
<asp:BoundField ReadOnly="True" HeaderText="SUBMITTED" InsertVisible="False" DataField="sumt_by"
SortExpression="Productqty">
<ItemStyle HorizontalAlign="Center"></ItemStyle>
</asp:BoundField>
<asp:BoundField ReadOnly="True" HeaderText="COUNT" InsertVisible="False" DataField="qt_count"
SortExpression="Productqty">
<ItemStyle HorizontalAlign="Center"></ItemStyle>
</asp:BoundField>
<asp:TemplateField>
<ItemTemplate>
<center>
<asp:ImageButton ID="download_img_btn" runat="server" Style="width: 15px; height: 15px;"
ImageUrl="Images\dwn_img.jpg" CommandName="BIenqDocDownload" ToolTip="Boldrocchi Enquiry Download" /></center>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</div>
protected void NestedGridView_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "GetComparative") // button click on footer template to get comparative chart
{
alert_message(" Comparative Chart working");
}
if (e.CommandName == "SupDocDownload") // For boldrocchi enquiry download
{
alert_message("sridhar");
int index = Convert.ToInt32(e.CommandArgument); // get the row index this will work if commandargument is defined gridview column
//alert_message(index.ToString ());
GridViewRow childGridViewRow = (GridViewRow)(((ImageButton)e.CommandSource).NamingContainer);
//GridView NestedGridView = childGridViewRow.FindControl("NestedGridView") as GridView;
GridView childGrid = childGridViewRow.NamingContainer as GridView;
GridViewRow parentRow = childGrid.NamingContainer as GridViewRow;
//phew! lets wrap it up into a single step.
GridViewRow optimisedParentRow = ((ImageButton)e.CommandSource).NamingContainer.NamingContainer.NamingContainer as GridViewRow;
if (optimisedParentRow != null)
{
GridView pgv = (GridView)optimisedParentRow.FindControl("RptSearch_Gridview");
//alert_message ( pgv.Rows[0].Cells[3].Text);
// Label lblEmptyGroupPK = (Label)optimisedParentRow.FindControl("lblEmptyGroupPK");
//TextBox txtEmptyFeatures = (TextBox)optimisedParentRow.FindControl("txtEmptyFeatures");
}
if (parentRow.RowType == DataControlRowType.DataRow)
{
// alert_message(parentRow.ToString());
}
string st = RptSearch_Gridview.Rows[index].Cells[3].Text;
}
}
Thanks,
Sridhar.