harmmeijer
Programmer
The url:
shows us how to do a one to many relationship in an updatable DataGrid.
This works for one to many not for one or zero to many, because the entire table is dumped in the dropdownlist.
If the DropDownList were to be filled with a rooms table the user is forced to choose a room since an empty record is not included in the DropDownList.
If this is my aspx page:
<%@ Page Language="vb" AutoEventWireup="false" Codebehind="WebForm2.aspx.vb" Inherits="mrrs.WebForm2" trace="true"%>
<form id="form1" runat="server">
<aspataGrid id="dgPlanner" runat="server" AutoGenerateColumns="False" OnEditCommand="dgPlannerEdit" OnCancelCommand="dgPlannerCancel">
<Columns>
<asp:TemplateColumn HeaderText="<b>Room</b>">
<ItemTemplate>
<%# Container.DataItem("RoomName" %>
</ItemTemplate>
<EditItemTemplate>
<aspropDownList
id="lstRooms"
runat="server"
DataValueField="ID"
DataTextField="RoomName" OnRenderContents = "selRender"
DataSource="<%# GetCategories() %>" even if I try to get the dropdown in the getCategories function it is nothing, so adding the empty record in this function won't work
/>
</EditItemTemplate>
</asp:TemplateColumn>
<asp:EditCommandColumn EditText="Edit" UpdateText="<b>Update</b>" CancelText="<b>Cancel</b>" HeaderText="<b>Edit</b>" />
</Columns>
</aspataGrid>
</form>
And I am using the ItemDataBound of the dgPlanner lstRooms is never anything else than nothing, here is the code behind:
Protected WithEvents dgPlanner As System.Web.UI.WebControls.DataGrid
...
Private Sub ItemDataBound(ByVal sender As Object, ByVal e As DataGridItemEventArgs) Handles dgPlanner.ItemDataBound
Dim intRow As Int16 = e.Item.ItemIndex
Dim lngSelectedID As Long = 0
If intRow > -1 Then
If intRow = dgPlanner.EditItemIndex Then
Dim str As String = ""
lngSelectedID = e.Item.DataItem("requestID"
' useless to try so why bother, it will allways be nothing Page.FindControl("lstRooms"
' if I could get my hands on the lstRooms here I could insert the table and an empty record in the dropdown
End If
End If
End Sub
The question is:
Where do I insert the empty record in the dropdownlist?
shows us how to do a one to many relationship in an updatable DataGrid.
This works for one to many not for one or zero to many, because the entire table is dumped in the dropdownlist.
If the DropDownList were to be filled with a rooms table the user is forced to choose a room since an empty record is not included in the DropDownList.
If this is my aspx page:
<%@ Page Language="vb" AutoEventWireup="false" Codebehind="WebForm2.aspx.vb" Inherits="mrrs.WebForm2" trace="true"%>
<form id="form1" runat="server">
<aspataGrid id="dgPlanner" runat="server" AutoGenerateColumns="False" OnEditCommand="dgPlannerEdit" OnCancelCommand="dgPlannerCancel">
<Columns>
<asp:TemplateColumn HeaderText="<b>Room</b>">
<ItemTemplate>
<%# Container.DataItem("RoomName" %>
</ItemTemplate>
<EditItemTemplate>
<aspropDownList
id="lstRooms"
runat="server"
DataValueField="ID"
DataTextField="RoomName" OnRenderContents = "selRender"
DataSource="<%# GetCategories() %>" even if I try to get the dropdown in the getCategories function it is nothing, so adding the empty record in this function won't work
/>
</EditItemTemplate>
</asp:TemplateColumn>
<asp:EditCommandColumn EditText="Edit" UpdateText="<b>Update</b>" CancelText="<b>Cancel</b>" HeaderText="<b>Edit</b>" />
</Columns>
</aspataGrid>
</form>
And I am using the ItemDataBound of the dgPlanner lstRooms is never anything else than nothing, here is the code behind:
Protected WithEvents dgPlanner As System.Web.UI.WebControls.DataGrid
...
Private Sub ItemDataBound(ByVal sender As Object, ByVal e As DataGridItemEventArgs) Handles dgPlanner.ItemDataBound
Dim intRow As Int16 = e.Item.ItemIndex
Dim lngSelectedID As Long = 0
If intRow > -1 Then
If intRow = dgPlanner.EditItemIndex Then
Dim str As String = ""
lngSelectedID = e.Item.DataItem("requestID"
' useless to try so why bother, it will allways be nothing Page.FindControl("lstRooms"
' if I could get my hands on the lstRooms here I could insert the table and an empty record in the dropdown
End If
End If
End Sub
The question is:
Where do I insert the empty record in the dropdownlist?