Nested Gridview Asp.net 2.0 C#
Nested GridView with Asp.Net 2.0 C#
Kashyap Patel (
[email protected])
Nested Gridview Asp.net 2.0 C#
Kashyap Patel (
[email protected])
Nested Gridview Asp.net 2.0 C#
Kashyap Patel (
[email protected])
Nested Gridview Asp.net 2.0 C#
Kashyap Patel (
[email protected])
Nested Gridview Asp.net 2.0 C#
Kashyap Patel (
[email protected])
Nested Gridview Asp.net 2.0 C#
Kashyap Patel (
[email protected])
Nested Gridview Asp.net 2.0 C#
Default.aspx Design Page <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
Nested GridView
Kashyap Patel (
[email protected])
Nested Gridview Asp.net 2.0 C#
Default.aspx.cs using using using using using using using using using using
System; System.Data; System.Configuration; System.Web; System.Web.Security; System.Web.UI; System.Web.UI.WebControls; System.Web.UI.WebControls.WebParts; System.Web.UI.HtmlControls; System.Data.SqlClient;
public partial class _Default : System.Web.UI.Page { SqlConnection con = new SqlConnection(@"Data Source=SYSTE01\SQLEXPRESS;Initial Catalog=DemoDB;Integrated Security=True;Pooling=False"); protected void Page_Load(object sender, EventArgs e) { //Bind State with parent gridview try { con.Open(); SqlDataAdapter adpState = new SqlDataAdapter("SELECT * FROM State", con); DataTable dtState = new DataTable(); adpState.Fill(dtState); // Fill data table with fetch records con.Close(); grdParent.DataSource = dtState; grdParent.DataBind(); } catch (Exception ex) { Response.Write(ex.Message); } } protected void grdParent_RowCommand(object sender, GridViewCommandEventArgs e) {
Kashyap Patel (
[email protected])
Nested Gridview Asp.net 2.0 C# try { //Checking for command name which command/button is pressed if (e.CommandName == "btnView") { //Find the which row buttom is pressed int RowIndex = Convert.ToInt32(e.CommandArgument); //Get State ID form the gridview int RecordID = Convert.ToInt32(((GridView)e.CommandSource).Rows[RowIndex].Cells[0].Text); con.Open(); SqlDataAdapter adpCity = new SqlDataAdapter("SELECT CityName FROM City where StateID=" + RecordID, con); DataTable dtCity = new DataTable(); adpCity.Fill(dtCity);
//Bind Data with gridview with contorl found on that row ((GridView)grdParent.Rows[RowIndex].FindControl("grdInner")).DataSource = dtCity; ((GridView)grdParent.Rows[RowIndex].FindControl("grdInner")).DataBind(); con.Close(); } } catch(Exception ex) { Response.Write(ex.Message); } } }
Kashyap Patel (
[email protected])
Nested Gridview Asp.net 2.0 C#
Kashyap Patel (
[email protected])