EditCommand on Nested DataGrid

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Chad Folden

    #1

    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=Fal se
    AllowSorting=Fa lse Runat=server
    AutoGenerateCol umns="False"
    GridLines="Hori zontal"
    ShowHeader=Fals e ShowFooter=Fals e width=100%
    BorderStyle="No ne"
    CellPadding="0"
    OnEditCommand=" _dgProj_EditCom mand"
    DataKeyField="P rojID" >

    <Columns>
    <asp:EditComman dColumn EditText="Edit
    This" CancelText="Can cel This" UpdateText="Upd ate This" />
    <asp:BoundColum n DataField=ProjI D
    HeaderText="Pro jID" />
    <asp:TemplateCo lumn>
    <ItemTemplate >
    <asp:DataGrid ID="_dgRel"
    AllowPaging=Fal se AllowSorting=Fa lse Runat=server
    AutoGenerateCol umns="False"
    GridLines="None "
    ShowHeader=fals e ShowFooter=Fals e width=100%
    BorderStyle="No ne"
    CellPadding="0"
    OnEditCommand=" _dgRel_EditComm and"
    DataKeyField="R elID"
    DataSource='<%# CType
    (Container.Data Item,System.Dat a.DataRowView). CreateChildVie
    w("RelID") %>'[color=blue]
    >[/color]
    <Columns>
    <asp:EditComman dColumn
    EditText="Edit This" CancelText="Can cel This"
    UpdateText="Upd ate This" />
    <asp:BoundColum n
    DataField=RelID HeaderText="Rel ID" />
    </Columns>
    </asp:DataGrid>
    </ItemTemplate>
    </asp:TemplateCol umn>
    </Columns>
    </asp:DataGrid>

    --CODE BEHIND-----

    Imports System.Data
    Imports System.Data.Sql Client

    Public Class DataGridNesting
    Inherits System.Web.UI.P age
    Protected WithEvents _dgProj As
    System.Web.UI.W ebControls.Data Grid
    Protected WithEvents _dgRel As
    System.Web.UI.W ebControls.Data Grid


    #Region " Web Form Designer Generated Code "

    'This call is required by the Web Form Designer.
    <System.Diagnos tics.DebuggerSt epThrough()> Private Sub
    InitializeCompo nent()

    End Sub

    Private Sub Page_Init(ByVal sender As System.Object,
    ByVal e As System.EventArg s) Handles MyBase.Init
    'CODEGEN: This method call is required by the Web
    Form Designer
    'Do not modify it using the code editor.
    InitializeCompo nent()
    End Sub

    #End Region

    Private Sub Page_Load(ByVal sender As System.Object,
    ByVal e As System.EventArg s) 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. ConfigurationSe ttings.AppSetti ngs
    ("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, "tblProject s")
    daRelease.Fill( DS, "tblRelease ")

    'Join (Many)
    tblRelease.Proj ID=tblProjects. ProjID(One)
    Dim RelIDParent As DataColumn = DS.Tables
    ("tblProjects") .Columns("ProjI D")
    Dim RelIDChild As DataColumn = DS.Tables
    ("tblRelease"). Columns("ProjID ")
    Dim RelIDRel As DataRelation = New DataRelation
    ("RelID", RelIDParent, RelIDChild, False)
    DS.Relations.Ad d(RelIDRel)

    _dgProj.DataSou rce = DS.Tables
    ("tblProjects") .DefaultView
    _dgProj.DataBin d()

    Catch ex As SqlException

    End Try

    End Sub

    Public Sub _dgProj_EditCom mand(ByVal source As Object,
    ByVal e As
    System.Web.UI.W ebControls.Data GridCommandEven tArgs)
    Handles _dgProj.EditCom mand
    source.EditItem Index = e.Item.ItemInde x
    BindDg()
    End Sub

    Public Sub _dgProj_CancelC ommand(ByVal source As
    Object, ByVal e As
    System.Web.UI.W ebControls.Data GridCommandEven tArgs)
    Handles _dgProj.CancelC ommand
    source.EditItem Index = -1
    BindDg()
    End Sub

    Public Sub _dgRel_EditComm and(ByVal source As Object,
    ByVal e As
    System.Web.UI.W ebControls.Data GridCommandEven tArgs)
    Handles _dgRel.EditComm and
    source.EditItem Index = e.Item.ItemInde x
    BindDg()
    End Sub

    Public Sub _dgRel_CancelCo mmand(ByVal source As
    Object, ByVal e As
    System.Web.UI.W ebControls.Data GridCommandEven tArgs)
    Handles _dgRel.CancelCo mmand
    source.EditItem Index = -1
    BindDg()
    End Sub
    End Class

Working...