I can't figure out how to use the EditCommand for the
nested datagrid .. HELP PLEASE ;-) It works perfectly for
the parent datagrid, but will not display, even though the
EditCommand event is firing for the child datagrid. I
have set up a test page for myself to see if I can get
this to work ..any help is appreciated! Thanks in advance
(This is my complete page and code behind)
<asp:DataGrid ID="_dgProj" AllowPaging=False
AllowSorting=False Runat=server
AutoGenerateColumns="False"
GridLines="Horizontal"
ShowHeader=False ShowFooter=False width=100%
BorderStyle="None"
CellPadding="0"
OnEditCommand="_dgProj_EditCommand"
DataKeyField="ProjID" >
<Columns>
<asp:EditCommandColumn EditText="Edit
This" CancelText="Cancel This" UpdateText="Update This" />
<asp:BoundColumn DataField=ProjID
HeaderText="ProjID" />
<asp:TemplateColumn>
<ItemTemplate>
<asp:DataGrid ID="_dgRel"
AllowPaging=False AllowSorting=False Runat=server
AutoGenerateColumns="False"
GridLines="None"
ShowHeader=false ShowFooter=False width=100%
BorderStyle="None"
CellPadding="0"
OnEditCommand="_dgRel_EditCommand"
DataKeyField="RelID"
DataSource='<%# CType
(Container.DataItem,System.Data.DataRowView).Creat eChildVie
w("RelID") %>'
<Columns>
<asp:EditCommandColumn
EditText="Edit This" CancelText="Cancel This"
UpdateText="Update This" />
<asp:BoundColumn
DataField=RelID HeaderText="RelID" />
</Columns>
</asp:DataGrid>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:DataGrid>
--CODE BEHIND-----
Imports System.Data
Imports System.Data.SqlClient
Public Class DataGridNesting
Inherits System.Web.UI.Page
Protected WithEvents _dgProj As
System.Web.UI.WebControls.DataGrid
Protected WithEvents _dgRel As
System.Web.UI.WebControls.DataGrid
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()
End Sub
Private Sub Page_Init(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web
Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub
#End Region
Private Sub Page_Load(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
If Page.IsPostBack = False Then
'Initialize first time page loads
BindDg()
End If
End Sub
Public Sub BindDg()
Dim DS As DataSet
Dim Conn1 As New SqlConnection
(Configuration.ConfigurationSettings.AppSettings
("connString"))
Try
Dim daProj As New SqlDataAdapter("SELECT *
FROM tblProjects", Conn1)
Dim daRelease As New SqlDataAdapter("SELECT *
FROM tblRelease", Conn1)
DS = New DataSet()
daProj.Fill(DS, "tblProjects")
daRelease.Fill(DS, "tblRelease")
'Join (Many)
tblRelease.ProjID=tblProjects.ProjID(One)
Dim RelIDParent As DataColumn = DS.Tables
("tblProjects").Columns("ProjID")
Dim RelIDChild As DataColumn = DS.Tables
("tblRelease").Columns("ProjID")
Dim RelIDRel As DataRelation = New DataRelation
("RelID", RelIDParent, RelIDChild, False)
DS.Relations.Add(RelIDRel)
_dgProj.DataSource = DS.Tables
("tblProjects").DefaultView
_dgProj.DataBind()
Catch ex As SqlException
End Try
End Sub
Public Sub _dgProj_EditCommand(ByVal source As Object,
ByVal e As
System.Web.UI.WebControls.DataGridCommandEventArgs )
Handles _dgProj.EditCommand
source.EditItemIndex = e.Item.ItemIndex
BindDg()
End Sub
Public Sub _dgProj_CancelCommand(ByVal source As
Object, ByVal e As
System.Web.UI.WebControls.DataGridCommandEventArgs )
Handles _dgProj.CancelCommand
source.EditItemIndex = -1
BindDg()
End Sub
Public Sub _dgRel_EditCommand(ByVal source As Object,
ByVal e As
System.Web.UI.WebControls.DataGridCommandEventArgs )
Handles _dgRel.EditCommand
source.EditItemIndex = e.Item.ItemIndex
BindDg()
End Sub
Public Sub _dgRel_CancelCommand(ByVal source As
Object, ByVal e As
System.Web.UI.WebControls.DataGridCommandEventArgs )
Handles _dgRel.CancelCommand
source.EditItemIndex = -1
BindDg()
End Sub
End Class