M
Morris Neuman
Hi,
I am trying to update a row in a GridView that uses a table with a join to
another table and using hidden column info for a parameter. I have set the
DataKeyNames for the GridView.
The page is working when I bind the GridView (GridView1) to my SqlDataDource
(SqlDataSource1), however it does not work when the GridView is bound to my
AccessDataSource (AccessDataSource1).
The page accesses 2 tables as follows:
1) Attendant which has AttendantID Text PK, TimeOfDay Int PK, Extension to
Dial Text.
2) AttTimeOfDayXref which has TimeOfDatNumber Int PK, TimeOfDayDescription
Text.
There is an Inner Join between the tables on the TimeOfDay and
TimeOfDayNumber fields.
My GridView is on the Content Page of a Master page. The GridView shows
fields from both tables
The source code below is set-up where DataSourceID="AccessDataSource1". You
can change to point to SqlDataSource to see it working.
Any help would be very much appreciated.
-------------------------------Source
Code------------------------------------------
<%@ Page Language="C#" MasterPageFile="~/MasterPage1.master"
Title="Admin-Manage Distribution List" %>
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
}
</script>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1"
Runat="Server">
<br />
<strong><span style="color: #000080; font-family: Verdana">
Manage Attendant Records<br />
</span></strong> <asp:Menu ID="Menu2" runat="server" BackColor="#FFC080"
BorderColor="Navy"
BorderStyle="Inset" BorderWidth="1px" Font-Bold="False"
Font-Strikeout="False"
Font-Underline="False" ForeColor="Navy" Orientation="Horizontal">
<StaticMenuStyle HorizontalPadding="5px" />
<StaticMenuItemStyle BackColor="#FFC080" Font-Names="verdana"
Font-Size="8pt"
HorizontalPadding="15px" />
<StaticHoverStyle Font-Bold="True" />
<Items>
<asp:MenuItem NavigateUrl="~/Default.aspx" Text="Message Center"
Value="Message Center" ToolTip="Review Mailboxes for logged in web account">
</asp:MenuItem>
<asp:MenuItem
NavigateUrl="~/systemadminOnly/ManageCALLMaster.aspx" Text="Manage CALLMaster"
Value="Manage CALLMaster" ToolTip="Manage CALLMaster
databases"></asp:MenuItem>
<asp:MenuItem
NavigateUrl="~/systemadminOnly/ManageWebAccounts.aspx" Text="Manage Web
Accounts"
Value="Manage Web Accounts" ToolTip="Manage Web
Accounts"></asp:MenuItem>
<asp:MenuItem
NavigateUrl="http://localhost/aspnetadmin/defaul...MWebManager\&applicationUrl=/TestAspnetConfig"
Text="Manage Roles/Web Account via ASP.Net" Value="Manage
via ASP.Net" ToolTip="Must be locally connected to web server"></asp:MenuItem>
</Items>
</asp:Menu>
<span style="font-family: Verdana; font-size: 10pt; color: navy;">
<br />
<br />
All Attendant Records </span>
<asp:GridView ID="GridView1" runat="server"
AllowPaging="True" AllowSorting="True"
AutoGenerateColumns="False" BorderColor="#FFC080"
BorderStyle="Solid" BorderWidth="1px"
DataKeyNames="AttendantID,TimeOfDay,TimeOfDayNumber,TimeOfDayDescription"
DataSourceID="AccessDataSource1"
Font-Size="8pt" CellPadding="5" CellSpacing="1" Font-Names="Verdana"
ForeColor="Navy">
<Columns>
<asp:CommandField ShowEditButton="True">
<ControlStyle Font-Bold="False" ForeColor="DarkSlateGray" />
<HeaderStyle BackColor="Lavender" />
<ItemStyle BackColor="Lavender" BorderColor="SlateGray"
BorderStyle="Inset" BorderWidth="2px" />
</asp:CommandField>
<asp:TemplateField>
<ControlStyle Font-Bold="False" ForeColor="DarkSlateGray" />
<ItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server"
OnClientClick="return confirm('Are you sure you want
to delete this Attendant Record?');"
CommandName="Delete">Delete</asp:LinkButton>
</ItemTemplate>
<ItemStyle BackColor="Lavender" BorderColor="SlateGray"
BorderStyle="Inset" BorderWidth="2px" />
<HeaderStyle BackColor="Lavender" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Attendant ID"
SortExpression="AttendantID">
<EditItemTemplate>
<asp:Label ID="Label7" runat="server" Text='<%#
Bind("AttendantID") %>'></asp:Label>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label7" runat="server" Text='<%#
Bind("AttendantID") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Time Of Day"
SortExpression="TimeOfDay"
Visible="False">
<EditItemTemplate>
<asp:Label ID="Label4" runat="server" Text='<%#
Bind("TimeOfDay") %>'></asp:Label>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label4" runat="server" Text='<%#
Bind("TimeOfDay") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="TimeOfDayNumber"
HeaderText="TimeOfDayNumber"
Visible="False" />
<asp:TemplateField HeaderText="Time Of Day Desc"
SortExpression="TimeOfDayDescription">
<EditItemTemplate>
<asp:Label ID="TimeOfDayDescription" runat="server"
Text='<%# Bind("TimeOfDayDescription")
%>'></asp:Label>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="TimeOfDayDescription" runat="server"
Text='<%# Bind("TimeOfDayDescription")
%>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="ExtensionToDial" HeaderText="Number
To Dial"
SortExpression="ExtensionToDial" />
</Columns>
<RowStyle BackColor="BlanchedAlmond" BorderStyle="None" />
<EmptyDataTemplate>
No mailboxes set-up for Member
<asp:LoginName ID="LoginName2" runat="server" />
</EmptyDataTemplate>
<HeaderStyle BackColor="#FFC080" Font-Bold="False"
BorderColor="#FFC080" />
<AlternatingRowStyle BackColor="SeaShell" />
<PagerSettings Mode="NumericFirstLast" />
</asp:GridView>
<asp:AccessDataSource ID="AccessDataSource1" runat="server"
DataFile="<%$ ConnectionStrings:CALLMasterMDB %>"
SelectCommand='SELECT Attendant.AttendantID, Attendant.TimeOfDay,
AttTimeOfDayXref.TimeOfDayDescription, Attendant.ExtensionToDial,
AttTimeOfDayXref.TimeOfDayNumber FROM (Attendant INNER JOIN AttTimeOfDayXref
ON Attendant.TimeOfDay = AttTimeOfDayXref.TimeOfDayNumber) ORDER BY
Attendant.AttendantID'
DeleteCommand="DELETE FROM Attendant WHERE (AttendantID = ?) AND
(TimeOfDay = ?)"
UpdateCommand="UPDATE Attendant SET Attendant.ExtensionToDial = ?
WHERE (((Attendant.AttendantID)=?) AND ((Attendant.TimeOfDay)=(Select
[TimeOfDayNumber] From AttTimeOfDayXref INNER JOIN Attendant ON
AttTimeOfDayXref.TimeOfDayNumber = Attendant.TimeOfDay Where
[TimeOfDayDescription]=?)));
">
<DeleteParameters>
<asparameter Name="AttendantID" Type="String" />
<asparameter Name="TimeOfDay" Type="Int32" />
</DeleteParameters>
<UpdateParameters>
<asparameter Name="ExtensionToDial" />
<asp:ControlParameter ControlID="GridView1" Name="AttendantID"
PropertyName="SelectedValue" Type="String" />
<asp:ControlParameter ControlID="GridView1"
Name="TimeOfDayDescription"
PropertyName="SelectedValue" Type="String" />
</UpdateParameters>
</asp:AccessDataSource>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:CallMasterSQLConnectionString %>"
SelectCommand="SELECT Attendant.AttendantID, Attendant.TimeOfDay,
AttTimeOfDayXref.TimeOfDayNumber, AttTimeOfDayXref.TimeOfDayDescription,
Attendant.ExtensionToDial FROM Attendant INNER JOIN AttTimeOfDayXref ON
Attendant.TimeOfDay = AttTimeOfDayXref.TimeOfDayNumber ORDER BY
Attendant.AttendantID"
DeleteCommand="DELETE FROM Attendant WHERE (AttendantID =
@AttendantID) AND (TimeOfDay = (SELECT TimeOfDayNumber FROM AttTimeOfDayXref
WHERE (TimeOfDayDescription = @TimeOfDayDescription)))"
UpdateCommand="UPDATE Attendant SET ExtensionToDial =
@ExtensionToDial FROM Attendant INNER JOIN AttTimeOfDayXref AS
AttTimeOfDayXref_1 ON Attendant.TimeOfDay =
AttTimeOfDayXref_1.TimeOfDayNumber WHERE (Attendant.AttendantID =
@AttendantID) AND (Attendant.TimeOfDay = (SELECT TimeOfDayNumber FROM
AttTimeOfDayXref WHERE (TimeOfDayDescription = @TimeOfDayDescription)))">
<DeleteParameters>
<asparameter Name="AttendantID" />
<asparameter Name="TimeOfDayDescription" />
</DeleteParameters>
<UpdateParameters>
<asparameter Name="ExtensionToDial" />
<asp:ControlParameter ControlID="GridView1" Name="AttendantID"
PropertyName="SelectedValue" />
<asp:ControlParameter ControlID="GridView1"
Name="TimeOfDayDescription"
PropertyName="SelectedValue" />
</UpdateParameters>
</asp:SqlDataSource>
<asp:AccessDataSource ID="AccessDataSource3" runat="server"
DataFile="C:\Program Files\CallMaster\Data\Callmaster.mdb"
SelectCommand="SELECT [TimeOfDayNumber], [TimeOfDayDescription] FROM
[AttTimeOfDayXref] ORDER BY [TimeOfDayNumber]">
</asp:AccessDataSource>
<asp:SqlDataSource ID="SqlDataSource3" runat="server"
ConnectionString="<%$ ConnectionStrings:CallMasterSQLConnectionString %>"
SelectCommand="SELECT [TimeOfDayNumber], [TimeOfDayDescription] FROM
[AttTimeOfDayXref] ORDER BY [TimeOfDayNumber]">
</asp:SqlDataSource>
<br />
<br />
<br />
<br />
<asp:HyperLink ID="HyperLink7" runat="server" Font-Names="Verdana"
Font-Size="8pt"
NavigateUrl="~/Default.aspx" ToolTip="Review Account Mailboxes,
Messages, Notifications"
Width="149px">Message Center</asp:HyperLink>
<asp:HyperLink ID="HyperLink6" runat="server"
Font-Names="Verdana" Font-Size="8pt"
NavigateUrl="~/systemadminOnly/ManageCALLMaster.aspx"
ToolTip="Maintain CALLMaster Database" Visible='<%#
User.IsInRole("systemadmin") %>'
Width="170px">Manage CALLMaster</asp:HyperLink>
<asp:HyperLink ID="HyperLink1" runat="server" Font-Names="Verdana"
Font-Size="8pt"
NavigateUrl="~/systemadminOnly/ManageWebAccounts.aspx"
Width="196px">Manage Web Accounts</asp:HyperLink>
<asp:HyperLink ID="HyperLink8" runat="server" Font-Names="Verdana"
Font-Size="8pt"
NavigateUrl="http://localhost/aspnetadmin/defaul...MWebManager\&applicationUrl=/TestAspnetConfig"
ToolTip="From Local Machine ONLY" Width="252px">Manage Roles/Web
Account via ASP.Net</asp:HyperLink><br />
<br />
<br />
</asp:Content>
I am trying to update a row in a GridView that uses a table with a join to
another table and using hidden column info for a parameter. I have set the
DataKeyNames for the GridView.
The page is working when I bind the GridView (GridView1) to my SqlDataDource
(SqlDataSource1), however it does not work when the GridView is bound to my
AccessDataSource (AccessDataSource1).
The page accesses 2 tables as follows:
1) Attendant which has AttendantID Text PK, TimeOfDay Int PK, Extension to
Dial Text.
2) AttTimeOfDayXref which has TimeOfDatNumber Int PK, TimeOfDayDescription
Text.
There is an Inner Join between the tables on the TimeOfDay and
TimeOfDayNumber fields.
My GridView is on the Content Page of a Master page. The GridView shows
fields from both tables
The source code below is set-up where DataSourceID="AccessDataSource1". You
can change to point to SqlDataSource to see it working.
Any help would be very much appreciated.
-------------------------------Source
Code------------------------------------------
<%@ Page Language="C#" MasterPageFile="~/MasterPage1.master"
Title="Admin-Manage Distribution List" %>
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
}
</script>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1"
Runat="Server">
<br />
<strong><span style="color: #000080; font-family: Verdana">
Manage Attendant Records<br />
</span></strong> <asp:Menu ID="Menu2" runat="server" BackColor="#FFC080"
BorderColor="Navy"
BorderStyle="Inset" BorderWidth="1px" Font-Bold="False"
Font-Strikeout="False"
Font-Underline="False" ForeColor="Navy" Orientation="Horizontal">
<StaticMenuStyle HorizontalPadding="5px" />
<StaticMenuItemStyle BackColor="#FFC080" Font-Names="verdana"
Font-Size="8pt"
HorizontalPadding="15px" />
<StaticHoverStyle Font-Bold="True" />
<Items>
<asp:MenuItem NavigateUrl="~/Default.aspx" Text="Message Center"
Value="Message Center" ToolTip="Review Mailboxes for logged in web account">
</asp:MenuItem>
<asp:MenuItem
NavigateUrl="~/systemadminOnly/ManageCALLMaster.aspx" Text="Manage CALLMaster"
Value="Manage CALLMaster" ToolTip="Manage CALLMaster
databases"></asp:MenuItem>
<asp:MenuItem
NavigateUrl="~/systemadminOnly/ManageWebAccounts.aspx" Text="Manage Web
Accounts"
Value="Manage Web Accounts" ToolTip="Manage Web
Accounts"></asp:MenuItem>
<asp:MenuItem
NavigateUrl="http://localhost/aspnetadmin/defaul...MWebManager\&applicationUrl=/TestAspnetConfig"
Text="Manage Roles/Web Account via ASP.Net" Value="Manage
via ASP.Net" ToolTip="Must be locally connected to web server"></asp:MenuItem>
</Items>
</asp:Menu>
<span style="font-family: Verdana; font-size: 10pt; color: navy;">
<br />
<br />
All Attendant Records </span>
<asp:GridView ID="GridView1" runat="server"
AllowPaging="True" AllowSorting="True"
AutoGenerateColumns="False" BorderColor="#FFC080"
BorderStyle="Solid" BorderWidth="1px"
DataKeyNames="AttendantID,TimeOfDay,TimeOfDayNumber,TimeOfDayDescription"
DataSourceID="AccessDataSource1"
Font-Size="8pt" CellPadding="5" CellSpacing="1" Font-Names="Verdana"
ForeColor="Navy">
<Columns>
<asp:CommandField ShowEditButton="True">
<ControlStyle Font-Bold="False" ForeColor="DarkSlateGray" />
<HeaderStyle BackColor="Lavender" />
<ItemStyle BackColor="Lavender" BorderColor="SlateGray"
BorderStyle="Inset" BorderWidth="2px" />
</asp:CommandField>
<asp:TemplateField>
<ControlStyle Font-Bold="False" ForeColor="DarkSlateGray" />
<ItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server"
OnClientClick="return confirm('Are you sure you want
to delete this Attendant Record?');"
CommandName="Delete">Delete</asp:LinkButton>
</ItemTemplate>
<ItemStyle BackColor="Lavender" BorderColor="SlateGray"
BorderStyle="Inset" BorderWidth="2px" />
<HeaderStyle BackColor="Lavender" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Attendant ID"
SortExpression="AttendantID">
<EditItemTemplate>
<asp:Label ID="Label7" runat="server" Text='<%#
Bind("AttendantID") %>'></asp:Label>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label7" runat="server" Text='<%#
Bind("AttendantID") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Time Of Day"
SortExpression="TimeOfDay"
Visible="False">
<EditItemTemplate>
<asp:Label ID="Label4" runat="server" Text='<%#
Bind("TimeOfDay") %>'></asp:Label>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label4" runat="server" Text='<%#
Bind("TimeOfDay") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="TimeOfDayNumber"
HeaderText="TimeOfDayNumber"
Visible="False" />
<asp:TemplateField HeaderText="Time Of Day Desc"
SortExpression="TimeOfDayDescription">
<EditItemTemplate>
<asp:Label ID="TimeOfDayDescription" runat="server"
Text='<%# Bind("TimeOfDayDescription")
%>'></asp:Label>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="TimeOfDayDescription" runat="server"
Text='<%# Bind("TimeOfDayDescription")
%>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="ExtensionToDial" HeaderText="Number
To Dial"
SortExpression="ExtensionToDial" />
</Columns>
<RowStyle BackColor="BlanchedAlmond" BorderStyle="None" />
<EmptyDataTemplate>
No mailboxes set-up for Member
<asp:LoginName ID="LoginName2" runat="server" />
</EmptyDataTemplate>
<HeaderStyle BackColor="#FFC080" Font-Bold="False"
BorderColor="#FFC080" />
<AlternatingRowStyle BackColor="SeaShell" />
<PagerSettings Mode="NumericFirstLast" />
</asp:GridView>
<asp:AccessDataSource ID="AccessDataSource1" runat="server"
DataFile="<%$ ConnectionStrings:CALLMasterMDB %>"
SelectCommand='SELECT Attendant.AttendantID, Attendant.TimeOfDay,
AttTimeOfDayXref.TimeOfDayDescription, Attendant.ExtensionToDial,
AttTimeOfDayXref.TimeOfDayNumber FROM (Attendant INNER JOIN AttTimeOfDayXref
ON Attendant.TimeOfDay = AttTimeOfDayXref.TimeOfDayNumber) ORDER BY
Attendant.AttendantID'
DeleteCommand="DELETE FROM Attendant WHERE (AttendantID = ?) AND
(TimeOfDay = ?)"
UpdateCommand="UPDATE Attendant SET Attendant.ExtensionToDial = ?
WHERE (((Attendant.AttendantID)=?) AND ((Attendant.TimeOfDay)=(Select
[TimeOfDayNumber] From AttTimeOfDayXref INNER JOIN Attendant ON
AttTimeOfDayXref.TimeOfDayNumber = Attendant.TimeOfDay Where
[TimeOfDayDescription]=?)));
">
<DeleteParameters>
<asparameter Name="AttendantID" Type="String" />
<asparameter Name="TimeOfDay" Type="Int32" />
</DeleteParameters>
<UpdateParameters>
<asparameter Name="ExtensionToDial" />
<asp:ControlParameter ControlID="GridView1" Name="AttendantID"
PropertyName="SelectedValue" Type="String" />
<asp:ControlParameter ControlID="GridView1"
Name="TimeOfDayDescription"
PropertyName="SelectedValue" Type="String" />
</UpdateParameters>
</asp:AccessDataSource>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:CallMasterSQLConnectionString %>"
SelectCommand="SELECT Attendant.AttendantID, Attendant.TimeOfDay,
AttTimeOfDayXref.TimeOfDayNumber, AttTimeOfDayXref.TimeOfDayDescription,
Attendant.ExtensionToDial FROM Attendant INNER JOIN AttTimeOfDayXref ON
Attendant.TimeOfDay = AttTimeOfDayXref.TimeOfDayNumber ORDER BY
Attendant.AttendantID"
DeleteCommand="DELETE FROM Attendant WHERE (AttendantID =
@AttendantID) AND (TimeOfDay = (SELECT TimeOfDayNumber FROM AttTimeOfDayXref
WHERE (TimeOfDayDescription = @TimeOfDayDescription)))"
UpdateCommand="UPDATE Attendant SET ExtensionToDial =
@ExtensionToDial FROM Attendant INNER JOIN AttTimeOfDayXref AS
AttTimeOfDayXref_1 ON Attendant.TimeOfDay =
AttTimeOfDayXref_1.TimeOfDayNumber WHERE (Attendant.AttendantID =
@AttendantID) AND (Attendant.TimeOfDay = (SELECT TimeOfDayNumber FROM
AttTimeOfDayXref WHERE (TimeOfDayDescription = @TimeOfDayDescription)))">
<DeleteParameters>
<asparameter Name="AttendantID" />
<asparameter Name="TimeOfDayDescription" />
</DeleteParameters>
<UpdateParameters>
<asparameter Name="ExtensionToDial" />
<asp:ControlParameter ControlID="GridView1" Name="AttendantID"
PropertyName="SelectedValue" />
<asp:ControlParameter ControlID="GridView1"
Name="TimeOfDayDescription"
PropertyName="SelectedValue" />
</UpdateParameters>
</asp:SqlDataSource>
<asp:AccessDataSource ID="AccessDataSource3" runat="server"
DataFile="C:\Program Files\CallMaster\Data\Callmaster.mdb"
SelectCommand="SELECT [TimeOfDayNumber], [TimeOfDayDescription] FROM
[AttTimeOfDayXref] ORDER BY [TimeOfDayNumber]">
</asp:AccessDataSource>
<asp:SqlDataSource ID="SqlDataSource3" runat="server"
ConnectionString="<%$ ConnectionStrings:CallMasterSQLConnectionString %>"
SelectCommand="SELECT [TimeOfDayNumber], [TimeOfDayDescription] FROM
[AttTimeOfDayXref] ORDER BY [TimeOfDayNumber]">
</asp:SqlDataSource>
<br />
<br />
<br />
<br />
<asp:HyperLink ID="HyperLink7" runat="server" Font-Names="Verdana"
Font-Size="8pt"
NavigateUrl="~/Default.aspx" ToolTip="Review Account Mailboxes,
Messages, Notifications"
Width="149px">Message Center</asp:HyperLink>
<asp:HyperLink ID="HyperLink6" runat="server"
Font-Names="Verdana" Font-Size="8pt"
NavigateUrl="~/systemadminOnly/ManageCALLMaster.aspx"
ToolTip="Maintain CALLMaster Database" Visible='<%#
User.IsInRole("systemadmin") %>'
Width="170px">Manage CALLMaster</asp:HyperLink>
<asp:HyperLink ID="HyperLink1" runat="server" Font-Names="Verdana"
Font-Size="8pt"
NavigateUrl="~/systemadminOnly/ManageWebAccounts.aspx"
Width="196px">Manage Web Accounts</asp:HyperLink>
<asp:HyperLink ID="HyperLink8" runat="server" Font-Names="Verdana"
Font-Size="8pt"
NavigateUrl="http://localhost/aspnetadmin/defaul...MWebManager\&applicationUrl=/TestAspnetConfig"
ToolTip="From Local Machine ONLY" Width="252px">Manage Roles/Web
Account via ASP.Net</asp:HyperLink><br />
<br />
<br />
</asp:Content>