Sarita Yadav

Sarita Yadav

  • NA
  • 21
  • 1.6k

Nested gridview is not bind on click of linkbutton parent gv

Aug 17 2015 7:32 AM
I have one parent gridview in which linkbutton is there..onclick of linkbutton of that particular row the child grid for the row should be binded with value..
here is the code
 
Aspx:-
 
<asp:GridView ID="grdOrderDetails" runat="server" OnRowCommand="grdOrderDetails_RowCommand" OnRowDataBound="grdOrderDetails_RowDataBound"
OnPageIndexChanging="grdOrderDetails_PageIndexChanging" AllowPaging="true" AutoGenerateColumns="false" DataKeyNames="OrderId">
<Columns>
<asp:TemplateField HeaderText="OrderID" Visible="false">
<ItemTemplate>
<asp:Label ID="lblOrderId" runat="server" Text='<%# Eval("OrderId") %>'></asp:Label>
<asp:Panel ID="Panel1" runat="server" >
<asp:GridView ID="grdDispatch" runat="server" AutoGenerateColumns="false" AllowPaging="true" OnRowEditing="grdDispatch_Editing">
<Columns>
<asp:BoundField DataField="OrderId" HeaderText="Order Id" />
<asp:BoundField DataField="ClientName" HeaderText="Client Name" />
<asp:TemplateField HeaderText="Dispatch Date">
<EditItemTemplate>
<asp:TextBox ID="txtDispatchDate" runat="server" CssClass="datePickerTextBox"></asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Courier Name">
<EditItemTemplate>
<asp:DropDownList ID="ddlCourier" runat="server"></asp:DropDownList>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Courier Receipt No.">
<EditItemTemplate>
<asp:TextBox ID="txtCourierNo" runat="server"></asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Dipatch">
<ItemTemplate>
<asp:Button ID="btnUpdate" runat="server" Text="Dispatch" OnClick="btnUpdate_Click" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Cancel">
<ItemTemplate>
<asp:Button ID="btnCancel" runat="server" Text="Cancel" OnClick="btnCancelUpt_Click" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</asp:Panel>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Sr No.">
<ItemTemplate>
<asp:Label ID="lblSrNo" runat="server"><%# Container.DataItemIndex + 1 %></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="ClientName" HeaderText="Client Name" />
<asp:BoundField DataField="LocName" HeaderText="Location Name" />
<asp:BoundField DataField="AddressName" HeaderText="Address Name" />
<asp:BoundField DataField="UserName" HeaderText="User Name" />
<asp:BoundField DataField="Order_Date" HeaderText="Order Date" DataFormatString="{0:dd/MM/yyyy}" />
<asp:TemplateField HeaderText="Edit Order">
<ItemTemplate>
<a href="javascript:doit()" id="btnEdit" runat="server" onmouseover="this.style.cursor='pointer'">Edit</a>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Dispatch Order">
<ItemTemplate>
<asp:LinkButton ID="lnkDispatch" runat="server" Text="Dispatch" ></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Cancel Order">
<ItemTemplate>
<asp:LinkButton ID="btnCancel" runat="server" Text="Cancel" OnClientClick="return confirm('Are you sure you want to cancel this order?')" CommandName="cDelete" CommandArgument='<%#Eval("OrderId") %>'></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView> 
 
 C# code:-
 
protected void grdOrderDetails_RowDataBound(object sender, GridViewRowEventArgs e)
{
SqlConnection conn = ApplicationInfo.GetConnection();
if (e.Row.RowIndex != -1)
{
string bintOrderId = ((Label)e.Row.FindControl("lblOrderId")).Text.Trim();
HtmlAnchor Anchor = (HtmlAnchor)e.Row.FindControl("btnEdit");
Anchor.Attributes.Add("onclick", "GB_show('Order Details','/CMSAdmin/frmSalesOrder.aspx?OId=" + bintOrderId + "&OP=0',600,600,'')");
}
if (e.Row.RowType == DataControlRowType.DataRow)
{
string OrderId = grdOrderDetails.DataKeys[e.Row.RowIndex].Value.ToString();
GridView grdDispatch = e.Row.FindControl("grdDispatch") as GridView;
DataSet ds = DashBoardManger.Bind_Data_ByOrderId(conn, Convert.ToInt64(OrderId));
grdDispatch.DataSource = ds;
grdDispatch.DataBind();
}
 
 
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function () {
$("[id*=lnkDispatch]").click(function (e) {
$(this).closest("tr").next().remove();
});
$("[id*=lnkDispatch]").click(function (e) {
$(this).closest("tr").after("<tr><td></td><td colspan = '999'>" + $(this).next().html() + "</td></tr>")
//$(this).attr("src", "images/minus.png");
return false;
});

});

</script>