flaksfatlielp
New Member
I've been having this error with ASP.NET. and it just seems to be on going. I fix one thing then it leads to another error. I had this previous problem which I asked on here: Issue with inserts and updates. Now in the top answer, I was told to numerous things to help fix my code; however, after I inserted "DataKeyNames="ID"" as told I get this error... I have no idea why Now note in the gridview, i have a "DataKeyNames="ID", which is then linked to <asp:BoundField DataField="ID" Visible="false" /> Here is the Stack Trace:[HttpException (0x80004005): DataBinding: 'System.Data.DataRowView' does not contain a property with the name 'ID'.] System.Web.UI.DataBinder.GetPropertyValue(Object container, String propName) +9502089 System.Web.UI.WebControls.GridView.CreateChildControls(IEnumerable dataSource, Boolean dataBinding) +3140 System.Web.UI.WebControls.CompositeDataBoundControl.PerformDataBinding(IEnumerable data) +67 System.Web.UI.WebControls.GridView.PerformDataBinding(IEnumerable data) +14 System.Web.UI.WebControls.DataBoundControl.OnDataSourceViewSelectCallback(IEnumerable data) +123 System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback) +33 System.Web.UI.WebControls.DataBoundControl.PerformSelect() +138 System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +30 System.Web.UI.WebControls.GridView.DataBind() +4 System.Web.UI.WebControls.BaseDataBoundControl.EnsureDataBound() +105 System.Web.UI.WebControls.CompositeDataBoundControl.CreateChildControls() +75 System.Web.UI.Control.EnsureChildControls() +83 System.Web.UI.Control.PreRenderRecursiveInternal() +42 System.Web.UI.Control.PreRenderRecursiveInternal() +168 System.Web.UI.Control.PreRenderRecursiveInternal() +168 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +974My ASP.NET: <%@ Page Language="C#" AutoEventWireup="true" CodeFile="MedicalOffice.aspx.cs" Inherits="MedicalOffice" %> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> <link href="http://stackoverflow.com/questions/15891613/StyleSheet.css" rel="stylesheet" /> </head> <body> <form id="form1" runat="server"> <div> <h1>Maintain Patients<asp:SqlDataSource ID="sdDoctorList" runat="server" ConnectionString="<%$ ConnectionStrings:MedicalOfficeConnectionString %>" SelectCommand="uspDoctorList" SelectCommandType="StoredProcedure"></asp:SqlDataSource> <asp:SqlDataSource ID="sdPatient" runat="server" ConnectionString="<%$ ConnectionStrings:MedicalOfficeConnectionString %>" DeleteCommand="usp_PatientDelete" DeleteCommandType="StoredProcedure" InsertCommand="uspPatientInsert" InsertCommandType="StoredProcedure" SelectCommand="uspPatientSelectByIDOrSelectAll" SelectCommandType="StoredProcedure" UpdateCommand="uspPatientUpdate" UpdateCommandType="StoredProcedure"> <DeleteParameters> <asparameter Name="ID" Type="Int32" /> </DeleteParameters> <InsertParameters> <asparameter Name="OHIP" Type="String" /> <asparameter Name="FirstName" Type="String" /> <asparameter Name="LastName" Type="String" /> <asparameter DbType="Date" Name="DOB" /> <asparameter Name="VisitsPerYear" Type="Int32" /> <asparameter Name="DoctorID" Type="Int32" /> </InsertParameters> <SelectParameters> <asp:ControlParameter ControlID="DropDownList1" DefaultValue="http://stackoverflow.com/questions/15891613/0" Name="DoctorID" PropertyName="SelectedValue" Type="Int32" /> </SelectParameters> <UpdateParameters> <asparameter Name="ID" Type="Int32" /> <asparameter Name="OHIP" Type="String" /> <asparameter Name="FirstName" Type="String" /> <asparameter Name="LastName" Type="String" /> <asparameter DbType="Date" Name="DOB" /> <asparameter Name="VisitsPerYear" Type="Int32" /> <asparameter Name="DoctorID" Type="Int32" /> </UpdateParameters> </asp:SqlDataSource> </h1> <p>Select Patient By Doctor:<aspropDownList ID="DropDownList1" runat="server" AutoPostBack="True" DataSourceID="sdDoctorList" DataTextField="Doctor" DataValueField="ID" AppendDataBoundItems="True"> <asp:ListItem Value="http://stackoverflow.com/questions/15891613/0">All Doctors</asp:ListItem> </aspropDownList> <asp:GridView ID="GridView1" runat="server" AllowSorting="True" AutoGenerateColumns="False" BackColor="White" BorderColor="#336666" BorderStyle="Double" BorderWidth="3px" CellPadding="4" DataSourceID="sdPatient" GridLines="Horizontal" DataKeyNames="ID"> <Columns> <asp:CommandField ShowDeleteButton="True" ShowEditButton="True" /> <asp:BoundField DataField="ID" Visible="false" /> <asp:TemplateField HeaderText="OHIP" SortExpression="OHIP"> <EditItemTemplate> <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("OHIP") %>'></asp:TextBox> </EditItemTemplate> <ItemTemplate> <asp:Label ID="Label1" runat="server" Text='<%# Bind("OHIP") %>'></asp:Label> </ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="First Name" SortExpression="FirstName"> <EditItemTemplate> <asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("FirstName") %>'></asp:TextBox> </EditItemTemplate> <ItemTemplate> <asp:Label ID="Label2" runat="server" Text='<%# Bind("FirstName") %>'></asp:Label> </ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="Last Name" SortExpression="LastName"> <EditItemTemplate> <asp:TextBox ID="TextBox3" runat="server" Text='<%# Bind("LastName") %>'></asp:TextBox> </EditItemTemplate> <ItemTemplate> <asp:Label ID="Label3" runat="server" Text='<%# Bind("LastName") %>'></asp:Label> </ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="DOB" SortExpression="DOB"> <EditItemTemplate> <asp:TextBox ID="TextBox4" runat="server" Text='<%# Bind("DOB") %>'></asp:TextBox> </EditItemTemplate> <ItemTemplate> <asp:Label ID="Label4" runat="server" Text='<%# Bind("DOB") %>'></asp:Label> </ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="Visits Per Year" SortExpression="VisitsPerYear"> <EditItemTemplate> <asp:TextBox ID="TextBox5" runat="server" Text='<%# Bind("VisitsPerYear") %>'></asp:TextBox> </EditItemTemplate> <ItemTemplate> <asp:Label ID="Label5" runat="server" Text='<%# Bind("VisitsPerYear") %>'></asp:Label> </ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="Doctor" SortExpression="Doctor"> <EditItemTemplate> <aspropDownList ID="DropDownList2" runat="server" DataSourceID="sdDoctorList" DataTextField="Doctor" DataValueField="ID" SelectedValue='http://stackoverflow.com/questions/15891613/<%# Bind("DoctorID") %>' > </aspropDownList> </EditItemTemplate> <ItemTemplate> <asp:Label ID="Label6" runat="server" Text='<%# Bind("Doctor") %>'></asp:Label> </ItemTemplate> </asp:TemplateField> </Columns> <FooterStyle BackColor="White" ForeColor="#333333" /> <HeaderStyle BackColor="#336666" Font-Bold="True" ForeColor="White" /> <PagerStyle BackColor="#336666" ForeColor="White" HorizontalAlign="Center" /> <RowStyle BackColor="White" ForeColor="#333333" /> <SelectedRowStyle BackColor="#339966" Font-Bold="True" ForeColor="White" /> <SortedAscendingCellStyle BackColor="#F7F7F7" /> <SortedAscendingHeaderStyle BackColor="#487575" /> <SortedDescendingCellStyle BackColor="#E5E5E5" /> <SortedDescendingHeaderStyle BackColor="#275353" /> </asp:GridView>