Asked By
anonymous
7060 points
N/A
Posted on - 08/28/2011
We are going to create a report web form for a trading company where we require a grid inside a grid. Let us say if some user wants to see the number of trades in one grid and the details of the specific trade inside the another grid.
It will be like when user clicks on the row of the grid a child grid should opened displaying all the necessary details of the trade. All this needs to be implemented in asp.net with ajax. I am curious to know how we can implement this scenarios?
Thanks in advance.
How to add the grid inside a grid in asp.net with Ajax?
Create ASP.NET pages.Start a new folder and add all the ASP.NET pages to that folder.
Default.aspx
Rdaiobuttonfield.aspx
Checkboxfield.aspx
Insertthroughfooter.aspx
Write down the code for all of the following pages and make sure that they are all in the same folder. You could add some extra code to make your table a little bit complicated.
Cheers.
How to add the grid inside a grid in asp.net with Ajax?
Â
To create grid you can use this code.
Â
Imports System.Data
Imports System.Data.SqlClient
Imports System.Web.UI.WebControls
Partial Class VBSample
Inherits System.Web.UI.Page
Private con As New SqlConnection("Data Source=SureshDasari;Integrated Security=true;Initial Catalog=MySampleDB")
Â
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
If Not IsPostBack Then
BindGridview()
End If
End Sub
' This method is used to bind gridview from database
Protected Sub BindGridview()
con.Open()
Dim cmd As New SqlCommand("select TOP 4 CountryId,CountryName from Country", con)
Dim da As New SqlDataAdapter(cmd)
Dim ds As New DataSet()
da.Fill(ds)
con.Close()
gvParentGrid.DataSource = ds
gvParentGrid.DataBind()
Â
End Sub
Protected Sub gvUserInfo_RowDataBound(ByVal sender As Object, ByVal e As GridViewRowEventArgs)
If e.Row.RowType = DataControlRowType.DataRow Then
con.Open()
Dim gv As GridView = DirectCast(e.Row.FindControl("gvChildGrid"), GridView)
Dim CountryId As Integer = Convert.ToInt32(e.Row.Cells(1).Text)
Dim cmd As New SqlCommand("select * from State where CountryID=" & CountryId, con)
Dim da As New SqlDataAdapter(cmd)
Dim ds As New DataSet()
da.Fill(ds)
con.Close()
gv.DataSource = ds
gv.DataBind()
End If
End Sub
End Class