I am noob in ASP.NET/C#, but I will do my best to describe my problem as best as possible.
Now I have a gridview to which the sql source is bound; It captures the right information. The information about the gridview will vary depending on what is selected in the drop-down list that is outside the grid that works. The problem is updating and pasting.
After trying to update. (As soon as I click the "Edit" button on one of the columns), I get the following error message: "DropDownList2" has a SelectedValue value, which is invalid because it does not exist in the list of items. Parameter Name: Value
I split the columns into templates as shown below, so I can manage them more easily. Drop-down list 2 is in my editing template. It is connected to a data source; this is the same source as my first dropdownmenu, which works flawlessly. Therefore, I do not believe that it will be sql behind this procedure. However, I have this dropdownlist 2 related to Doctor. Now I was told to bind it, so I don’t know how the bindings work
If I untie it, I can at least see the grid even after I click the "Edit" button, but after updating I get an error message: The procedure or function uspPatientUpdate contains too many arguments.
Now I looked at the online solution, but I can not wrap my head around the binding. If necessary, I will give the following code.
ASP:
<asp:SqlDataSource ID="sdPatient" runat="server" ConnectionString="<%$ ConnectionStrings:MedicalOfficeConnectionString %>" DeleteCommand="usp_PatientDelete" InsertCommand="uspPatientInsert" SelectCommand="uspPatientSelectByIDOrSelectAll" UpdateCommand="uspPatientUpdate" SelectCommandType="StoredProcedure" DeleteCommandType="StoredProcedure" InsertCommandType="StoredProcedure" UpdateCommandType="StoredProcedure">
<DeleteParameters>
<asp:Parameter Name="ID" Type="Int32" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="OHIP" Type="String" />
<asp:Parameter Name="FirstName" Type="String" />
<asp:Parameter Name="LastName" Type="String" />
<asp:Parameter DbType="Date" Name="DOB" />
<asp:Parameter Name="VisitsPerYear" Type="Int32" />
<asp:Parameter Name="DoctorID" Type="Int32" />
<asp:Parameter Name="Timestamp" Type="Byte"></asp:Parameter>
</InsertParameters>
<SelectParameters>
<asp:ControlParameter ControlID="DropDownList1" Name="DoctorID" PropertyName="SelectedValue" Type="Int32" DefaultValue="0" />
</SelectParameters>
<UpdateParameters>
<asp:Parameter Name="ID" Type="Int32" />
<asp:Parameter Name="OHIP" Type="String" />
<asp:Parameter Name="FirstName" Type="String" />
<asp:Parameter Name="LastName" Type="String" />
<asp:Parameter DbType="Date" Name="DOB" />
<asp:Parameter Name="VisitsPerYear" Type="Int32" />
<asp:Parameter Name="DoctorID" Type="Int32" />
<asp:Parameter Name="ID" Type="Int32" />
<asp:Parameter Name="Timestamp" Type="Byte"></asp:Parameter>
</UpdateParameters>
</asp:SqlDataSource>
<p>Select Patient By Doctor:<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" DataSourceID="sdDoctorList" DataTextField="Doctor" DataValueField="ID" AppendDataBoundItems="True">
<asp:ListItem Value="0">All Doctors</asp:ListItem>
</asp:DropDownList>
<asp:GridView ID="GridView1" runat="server" AllowSorting="True" AutoGenerateColumns="False" BackColor="White" BorderColor="#336666" BorderStyle="Double" BorderWidth="3px" CellPadding="4" DataSourceID="sdPatient" GridLines="Horizontal">
<Columns>
<asp:CommandField ShowDeleteButton="True" ShowEditButton="True" />
<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>
<asp:DropDownList ID="DropDownList2" runat="server" DataSourceID="sdDoctorList" DataTextField="Doctor" DataValueField="ID" SelectedValue='<%# Bind("Doctor") %>'>
</asp:DropDownList>
</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>
Procedures:
This is for dropdowns. It gives a name as well as a meaning. * Note. This procedure works for the first drop-down list, and I believe for the second.
ALTER PROCEDURE dbo.uspDoctorList
AS
BEGIN
SET NOCOUNT ON
SELECT ID, LastName +', ' + FirstName AS 'Doctor'
FROM Doctor
ORDER BY 'Doctor'
END
This is an update procedure. Not sure if it's someone who is to blame or not, or if it's just my ASP
ALTER PROCEDURE dbo.uspPatientUpdate
@ID int,
@OHIP char(10),
@FirstName nvarchar(20),
@LastName nvarchar(40),
@DOB date,
@VisitsPerYear int,
@DoctorID int,
@Timestamp Timestamp
AS
BEGIN
SET NOCOUNT OFF
UPDATE Patient
SET OHIP = @OHIP,
FirstName = @FirstName,
LastName = @LastName,
DOB = @DOB,
VisitsPerYear = @VisitsPerYear,
DoctorID = @DoctorID
WHERE ID = @ID AND Timestamp = @Timestamp
END
I would be grateful for any help. By the way, this material is a little more than what we were taught (using stored procedures in ASP), I am learning an extra mile for bonus points. Thanks in advance.
If you need more information, please ask.