RE: Repeater with nested GridView edit problem



David,

Did you ever solve your problem? I'm experiencing nearly the exact same
situation.
I have gridviews nested inside Repeaters; both are tied to
ObjectDataSources. My gridviews will not go into edit mode when nested
inside the repeater (copying the grid and its ODS outside the repeater and
edit works fine). I'm not having the DataKeyNames problem you were.

Thanks,
Brett J.

"David" wrote:

Hi All,

I have a repeater control with a nested Gridview and i am having problems
with getting the gridview into edit mode.
I know I have to set the DataKeyNames value to my primary key field within
the datagrid view but as soon as I do this it generates an error and no data
is displayed.
I have tried using the parent primary key field which also doesnt work and
that wouldnt be correct anyway.
If i leave the DataKeyNames blank like the code below then my data is
dispalyed correctly but the edit mode obviously doesnt work because i havent
set the DataKeyNames value.

Thank you for any help recieved.

HTML code:

<asp:Repeater ID="rptPersonParent" runat="server">

<ItemTemplate>

<h2><%#DataBinder.Eval(Container.DataItem, "PersonName")%></h2>


<asp:GridView

ID="gvPersonParent"

runat="server"

AutoGenerateColumns="False"

ShowHeader="True"

OnRowEditing="Edit_Row"

AutoGenerateEditButton="False"

DataSource='<%#
Container.Dataitem.Row.GetChildRows("FK_Test2_EmpLoc_Test1_Person")%>'

DataKeyNames=""

EditRowStyle-BackColor="Yellow" >


<HeaderStyle ForeColor="#CCCCFF" Font-Bold="True"
BackColor="#003399"></HeaderStyle>

<Columns>

<asp:CommandField ShowEditButton="True" />



<asp:TemplateField HeaderText="Arrive">

<EditItemTemplate>

<asp:DropDownList ID="DropDownList1" runat="server"></asp:DropDownList>

<asp:Label ID="Label3" runat="server" Text=":"></asp:Label>

<asp:DropDownList ID="DropDownList2" runat="server"></asp:DropDownList>

</EditItemTemplate>

<ItemTemplate>

<%#GetTime(DataBinder.Eval(Container.DataItem, "(ArrTime)"))%>

</ItemTemplate>

</asp:TemplateField>

<asp:TemplateField HeaderText="Depart">

<ItemTemplate>

<%#GetTime(DataBinder.Eval(Container.DataItem, "(DepTime)"))%>

</ItemTemplate>

<EditItemTemplate>

<asp:DropDownList ID="DropDownList3" runat="server"></asp:DropDownList>

<asp:Label ID="Label4" runat="server" Text=":"></asp:Label>

<asp:DropDownList ID="DropDownList4" runat="server"></asp:DropDownList>

</EditItemTemplate>

</asp:TemplateField>

<asp:TemplateField HeaderText="Date">

<ItemTemplate>

<%#GetDate(DataBinder.Eval(Container.DataItem, "(ArrTime)"))%>

</ItemTemplate>

</asp:TemplateField>

<asp:TemplateField HeaderText="Location">

<ItemTemplate>

<%#DataBinder.Eval(Container.DataItem, "(Location)")%>

</ItemTemplate>

</asp:TemplateField>

</Columns>

<SelectedRowStyle ForeColor="#CCFF99" Font-Bold="True"
BackColor="#009999"></SelectedRowStyle>

<RowStyle ForeColor="#003399" BackColor="White"></RowStyle>

</asp:GridView>

</ItemTemplate>

</asp:Repeater>

Code behind:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
Handles Me.Load

Try

Me.divadd.Visible = False

objDataSet = RSKData.CreateDataSet

Me.rptPersonParent.DataSource = objDataSet.Tables("Person")

Me.rptPersonParent.DataBind()

PopulateTable()

Catch ex As Exception

'RSKData.WriteToLog("Page_Load" & ex.Message, 5)

End Try

End Sub



RSKData Class code:



Public Function CreateDataSet()

Try

Dim objThisCommand, objDepthisCommand As New
System.Data.SqlClient.SqlCommand

ConnectToDatabase(objThisCommand)

objDataset.Tables.Add(New System.Data.DataTable("Person"))

objThisCommand.CommandText = "Test1_Select_Person"

objThisCommand.CommandType = System.Data.CommandType.StoredProcedure

objDataAdapter.SelectCommand = objThisCommand

objThisCommand.Parameters.Clear()

objDataAdapter.Fill(objDataset.Tables("Person"))

objThisCommand = New System.Data.SqlClient.SqlCommand

ConnectToDatabase(objThisCommand)

objThisCommand.CommandText = "Test1_Update_Person"

objThisCommand.CommandType = System.Data.CommandType.StoredProcedure

objThisCommand.Parameters.Clear()

objDataAdapter.UpdateCommand = objThisCommand

With objDataAdapter.UpdateCommand

..Parameters.Add("@PersonName", System.Data.SqlDbType.VarChar)

..Parameters.Item("@PersonName").SourceColumn = "PersonName"

..Parameters.Add("@DepID", System.Data.SqlDbType.UniqueIdentifier)

..Parameters.Item("@DepID").SourceColumn = "DepID"

..Parameters.Add("@PersonID", System.Data.SqlDbType.UniqueIdentifier)

..Parameters.Item("@PersonID").SourceColumn = "PersonID"

End With

objThisCommand = New System.Data.SqlClient.SqlCommand

ConnectToDatabase(objThisCommand)

objThisCommand.CommandText = "Test1_Delete_Person"

objThisCommand.CommandType = System.Data.CommandType.StoredProcedure

objThisCommand.Parameters.Clear()

objDataAdapter.DeleteCommand = objThisCommand

With objDataAdapter.DeleteCommand

..Parameters.Add("@PersonID", System.Data.SqlDbType.UniqueIdentifier)

..Parameters.Item("@PersonID").SourceColumn = "PersonID"

End With

objThisCommand = New System.Data.SqlClient.SqlCommand

ConnectToDatabase(objThisCommand)

objThisCommand.CommandText = "Test1_Insert_Person"

objThisCommand.CommandType = System.Data.CommandType.StoredProcedure

objThisCommand.Parameters.Clear()

objDataAdapter.InsertCommand = objThisCommand

With objDataAdapter.InsertCommand

..Parameters.Add("@PersonName", System.Data.SqlDbType.VarChar)

..Parameters.Item("@PersonName").SourceColumn = "PersonName"

..Parameters.Add("@DepID", System.Data.SqlDbType.UniqueIdentifier)

..Parameters.Item("@DepID").SourceColumn = "DepID"

End With

AddHandler objDataAdapter.RowUpdated, New
SqlClient.SqlRowUpdatedEventHandler(AddressOf PersonOnRowUpdated)

AddHandler objDataAdapter.RowUpdating, New
SqlClient.SqlRowUpdatingEventHandler(AddressOf PersonOnRowUpdating)

ConnectToDatabase(objDepthisCommand)

objDataset.Tables.Add(New System.Data.DataTable("Department"))

objDepthisCommand.CommandText = "Test1_Select_Department"

objDepthisCommand.CommandType = System.Data.CommandType.StoredProcedure

objDepDataAdapter.SelectCommand = objDepthisCommand

objDepthisCommand.Parameters.Clear()

objDepDataAdapter.Fill(objDataset.Tables("Department"))



objDataset.Relations.Add("FK_Test1_Person_Test1_Department",
objDataset.Tables("Department").Columns("DepID"),
objDataset.Tables("Person").Columns("DepID"), True)

objDataset.Relations("FK_Test1_Person_Test1_Department").Nested = True

ConnectToDatabase(obj2ThisCommand)

objDataset.Tables.Add(New System.Data.DataTable("EmpLoc"))

obj2ThisCommand.CommandText = "Test2_Select_EmpLoc"

obj2ThisCommand.CommandType = System.Data.CommandType.StoredProcedure

obj2DataAdapter.SelectCommand = obj2ThisCommand

obj2ThisCommand.Parameters.Clear()

obj2DataAdapter.Fill(objDataset.Tables("EmpLoc"))



obj2ThisCommand.CommandText = "Test2_Insert_EmpLoc"

obj2ThisCommand.CommandType = System.Data.CommandType.StoredProcedure

.


Loading