469,625 Members | 1,690 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,625 developers. It's quick & easy.

EditCommand on Nested DataGrid

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

Nov 17 '05 #1
0 2118

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by bmoman | last post: by
4 posts views Thread by Richard Roche | last post: by
reply views Thread by Linus | last post: by
1 post views Thread by bill yeager | last post: by
1 post views Thread by jacobryce | last post: by
1 post views Thread by benoit | last post: by
1 post views Thread by Joe | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.