Nested Gridview With Asp.net C#

  • Uploaded by: Kashyap Patel
  • 0
  • 0
  • April 2020
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Nested Gridview With Asp.net C# as PDF for free.

More details

  • Words: 369
  • Pages: 10
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
<%--This button is used to call the event of display the city list--%> <%--This is the template field at where we can display result--%> <%--This is the inner girdview we bound city name here--%>


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])

Related Documents


More Documents from "Marco Antonio Enciso Salinas"