Pages

Sunday, 29 April 2012

How to Bind Data in Nested Gridview using Row Command Event


<ItemTemplate>
  <asp:Label ID="Label1" runat="server" Text='<%# Eval("name") %>'></asp:Label>
  <asp:LinkButton ID="linkButton1" CommandName="select" runat="server" Text="Select" />
</ItemTemplate>
 
and Implement the RowCommand Event:
 
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
  if (e.CommandName == "select")
  {
    GridViewRow row = (GridViewRow)(((LinkButton)e.CommandSource).NamingContainer);
 
    GridView Grid2 = (GridView)row.FindControl("NestedGrid");
 
    //Neste GridDAta
 
    Response.Write("----------Nested Grid Data-------------");
    foreach (GridViewRow Childrow in Grid2.Rows)
    {
      string stid = ((Label)Childrow.FindControl("Label1")).Text;
      string name = ((Label)Childrow.FindControl("Label2")).Text;
 
      Response.Write(stid);
      Response.Write("<br>");
      Response.Write(name);
    }
  }
}
 

No comments:

Post a Comment