I want to put the current date in my formview 'dateadded' but its not showing when I load it in the browser. I'm using code behind but how can I display it with date and time?
Here's a my code behind.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace LibrarySystem.AdminPage
{
public partial class ManageBooks : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if(FormView1.CurrentMode == FormViewMode.Insert)
{
TextBox dateadded = FormView1.FindControl("dateaddedTextBox") as TextBox;
dateadded.Text = DateTime.Now.ToString("d");
}
}
}
}
Here's my complete design
<%# Page Title="" Language="C#" MasterPageFile="~/Site1.Master" AutoEventWireup="true" CodeBehind="Lending.aspx.cs" Inherits="LibrarySystem.Test" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<h3>
Lending of Books</h3>
<p>
<asp:FormView ID="FormView1" runat="server" DataSourceID="lendDataSource" DefaultMode="Insert" OnDataBound="FormView1_DataBound">
<EditItemTemplate>
Book ID/ISBN:
<asp:TextBox ID="bookidTextBox" runat="server" Text='<%# Bind("bookid") %>' />
<br />
Book Title:
<asp:TextBox ID="booktitleTextBox" runat="server"
Text='<%# Bind("booktitle") %>' />
<br />
Employee ID:
<asp:TextBox ID="employeeidTextBox" runat="server"
Text='<%# Bind("employeeid") %>' />
<br />
Department:
<asp:TextBox ID="departmentTextBox" runat="server"
Text='<%# Bind("department") %>' />
<br />
Date borrowed:
<asp:TextBox ID="dateborrowedTextBox" runat="server"
Text='<%# Bind("dateborrowed") %>' />
<br />
<asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True"
CommandName="Update" Text="Update" />
<asp:LinkButton ID="UpdateCancelButton" runat="server"
CausesValidation="False" CommandName="Cancel" Text="Cancel" />
</EditItemTemplate>
<InsertItemTemplate>
Book:
<asp:DropDownList ID="DropDownList1" runat="server"
DataSourceID="booktitleDataSource" DataTextField="booktitle"
DataValueField="bookid" SelectedValue='<%# Bind("bookid", "{0}") %>'>
</asp:DropDownList>
<asp:SqlDataSource ID="booktitleDataSource" runat="server"
ConnectionString="<%$ ConnectionStrings:LibrarySystemConnectionString %>"
SelectCommand="SELECT [bookid], [booktitle] FROM [TblBooks]">
</asp:SqlDataSource>
<br />
Employee ID:
<asp:TextBox ID="employeeidTextBox" runat="server"
Text='<%# Bind("employeeid") %>' />
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="* Required" ControlToValidate="employeeidTextBox" ValidationGroup="lendbook">
</asp:RequiredFieldValidator>
<br />
Department:
<asp:TextBox ID="departmentTextBox" runat="server"
Text='<%# Bind("department") %>' />
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ErrorMessage="* Required" ControlToValidate="departmentTextBox" ValidationGroup="lendbook">
</asp:RequiredFieldValidator>
<br />
Date borrowed:
<asp:TextBox ID="dateborrowedTextBox" runat="server"
Text='<%# Bind("dateborrowed") %>' />
<asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ErrorMessage="* Required" ControlToValidate="dateborrowedTextBox" ValidationGroup="lendbook">
</asp:RequiredFieldValidator>
<br />
<asp:LinkButton ID="InsertButton" runat="server" CausesValidation="True" ValidationGroup="lendbook"
CommandName="Insert" Text="Insert" />
<asp:LinkButton ID="InsertCancelButton" runat="server" CausesValidation="False"
CommandName="Cancel" Text="Cancel" />
</InsertItemTemplate>
<ItemTemplate>
<asp:LinkButton ID="NewButton" runat="server" CausesValidation="False"
CommandName="New" Text="New" />
</ItemTemplate>
<EmptyDataTemplate>
<asp:LinkButton ID="NewButton" runat="server" CausesValidation="False"
CommandName="New" Text="New" />
</EmptyDataTemplate>
</asp:FormView>
</p>
<p>
<asp:SqlDataSource ID="lendDataSource" runat="server"
ConnectionString="<%$ ConnectionStrings:LibrarySystemConnectionString %>"
DeleteCommand="DELETE FROM [LendTable] WHERE [lenid] = #lenid"
InsertCommand="INSERT INTO [LendTable] ([bookid], [employeeid], [department], [dateborrowed], [datereturned]) VALUES (#bookid, #employeeid, #department, #dateborrowed, #datereturned)"
SelectCommand="SELECT dbo.LendTable.bookid, dbo.TblBooks.booktitle, dbo.LendTable.employeeid, dbo.LendTable.department, dbo.LendTable.dateborrowed FROM dbo.LendTable INNER JOIN dbo.TblBooks ON dbo.LendTable.bookid = dbo.TblBooks.bookid"
UpdateCommand="UPDATE [LendTable] SET [bookid] = #bookid, [employeeid] = #employeeid, [department] = #department, [dateborrowed] = #dateborrowed, [datereturned] = #datereturned WHERE [lenid] = #lenid">
<DeleteParameters>
<asp:Parameter Name="lenid" Type="Int32" />
</DeleteParameters>
<UpdateParameters>
<asp:Parameter Name="bookid" Type="Int64" />
<asp:Parameter Name="employeeid" Type="string" />
<asp:Parameter Name="department" Type="String" />
<asp:Parameter Name="dateborrowed" Type="DateTime" />
<asp:Parameter Name="datereturned" Type="DateTime" />
<asp:Parameter Name="lenid" Type="Int32" />
</UpdateParameters>
<InsertParameters>
<asp:Parameter Name="bookid" Type="Int64" />
<asp:Parameter Name="employeeid" Type="string" />
<asp:Parameter Name="department" Type="String" />
<asp:Parameter Name="dateborrowed" Type="DateTime" />
<asp:Parameter Name="datereturned" Type="DateTime" />
</InsertParameters>
</asp:SqlDataSource>
</p>
<p>
<asp:GridView ID="GridView1" runat="server" AllowPaging="True"
AllowSorting="True" AutoGenerateColumns="False" CellPadding="4"
DataKeyNames="lenid" DataSourceID="lendgridviewDataSource" ForeColor="#333333"
GridLines="None">
<RowStyle BackColor="#EFF3FB" />
<Columns>
<asp:CommandField ShowDeleteButton="True" ShowEditButton="True" />
<asp:BoundField DataField="bookid" HeaderText="Book ID/ISBN"
SortExpression="bookid" />
<asp:BoundField DataField="booktitle" HeaderText="Book Title"
SortExpression="booktitle" />
<asp:BoundField DataField="EmployeeID" HeaderText="Employee ID"
SortExpression="EmployeeID" />
<asp:BoundField DataField="department" HeaderText="Department"
SortExpression="department" />
<asp:BoundField DataField="dateborrowed" HeaderText="Date Borrowed"
SortExpression="dateborrowed" />
<asp:BoundField DataField="datereturned" HeaderText="Date Returned"
NullDisplayText="-- not yet returned --" SortExpression="datereturned" />
</Columns>
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<EditRowStyle BackColor="#2461BF" />
<AlternatingRowStyle BackColor="White" />
</asp:GridView>
<asp:SqlDataSource ID="lendgridviewDataSource" runat="server"
ConnectionString="<%$ ConnectionStrings:LibrarySystemConnectionString %>"
DeleteCommand="DELETE FROM [LendTable] WHERE [lenid] = #lenid"
InsertCommand="INSERT INTO [LendTable] ([bookid], [department], [EmployeeID], [dateborrowed], [datereturned]) VALUES (#bookid, #department, #EmployeeID, #dateborrowed, #datereturned)"
SelectCommand="SELECT dbo.LendTable.lenid, dbo.LendTable.bookid, dbo.LendTable.department, dbo.LendTable.EmployeeID, dbo.LendTable.dateborrowed, dbo.LendTable.datereturned, dbo.TblBooks.booktitle FROM dbo.LendTable INNER JOIN dbo.TblBooks ON dbo.LendTable.bookid = dbo.TblBooks.bookid"
UpdateCommand="UPDATE [LendTable] SET [bookid] = #bookid, [department] = #department, [EmployeeID] = #EmployeeID, [dateborrowed] = #dateborrowed, [datereturned] = #datereturned WHERE [lenid] = #lenid">
<DeleteParameters>
<asp:Parameter Name="lenid" Type="Int32" />
</DeleteParameters>
<UpdateParameters>
<asp:Parameter Name="bookid" Type="Int64" />
<asp:Parameter Name="department" Type="String" />
<asp:Parameter Name="EmployeeID" Type="String" />
<asp:Parameter Name="dateborrowed" Type="DateTime" />
<asp:Parameter Name="datereturned" Type="DateTime" />
<asp:Parameter Name="lenid" Type="Int32" />
</UpdateParameters>
<InsertParameters>
<asp:Parameter Name="bookid" Type="Int64" />
<asp:Parameter Name="department" Type="String" />
<asp:Parameter Name="EmployeeID" Type="String" />
<asp:Parameter Name="dateborrowed" Type="DateTime" />
<asp:Parameter Name="datereturned" Type="DateTime" />
</InsertParameters>
</asp:SqlDataSource>
</p>
<p>
<asp:HyperLink ID="HyperLink4" runat="server"
NavigateUrl="~/Admin/Returning.aspx">Returning</asp:HyperLink>
</p>
<asp:HyperLink ID="HyperLink5" runat="server"
NavigateUrl="~/Admin/AdminPage.aspx">Back to Admin Page</asp:HyperLink>
<p>
</p>
</asp:Content>
You have to use the Databound event for that...
protected void FormView1_DataBound(object sender, EventArgs e)
{
if (FormView1.CurrentMode == FormViewMode.Insert)
{
TextBox dateadded = FormView1.FindControl("dateaddedTextBox") as TextBox;
dateadded.Text = DateTime.Now.ToString("d");
}
}
Edit: You need to pass your Date Column in the inserting method of the DetailsView
protected void DetailsView1_ItemInserting(object sender, DetailsViewInsertEventArgs e)
{
e.Values["DateColumnName"] = ((TextBox)DetailsView1.FindControl("dateaddedTextBox")).Text;
}
Instead of doing that in your Page_Load() method, try doing it in the Page_PreRender() method.
Related
i have attached my gridview with id= "project_update_GridView" and Datasource. delete command works good but update command is not working.
some additional information:
This gridview is placed in a Modal Popup
All edit,update and delete command works well in empty webform but it doesn't works in my main solution webform
<div id="project_update_panel" class="popup " style="margin-left: 40px">
<label runat="server" id="project_overview"><i class='bx bx-sort-up'></i>Update Project<i id="close_popup_projectUP" class='bx bx-x-circle update-project-popup'></i></label>
<asp:Panel ID="project_update_popup_panel" runat="server" ScrollBars="Auto" CssClass="update-project-panel">
<%--update project Data source--%>
<asp:SqlDataSource ID="project_update_DS" runat="server" ConnectionString="<%$ ConnectionStrings:Timesheet_DBConnectionString %>" SelectCommand="SELECT [id], [employee_id], [project_id], [project_name], [product_name], [client_name], [project_team], [start_date], [project_team_email_id], [project_status] FROM [project_details] WHERE (([employee_id] = #employee_id) AND ([project_type] = #project_type))" DeleteCommand="DELETE FROM [project_details] WHERE [id] = #original_id" InsertCommand="INSERT INTO [project_details] ([employee_id], [project_id], [project_name], [product_name], [client_name], [project_team], [start_date], [project_team_email_id], [project_status]) VALUES (#employee_id, #project_id, #project_name, #product_name, #client_name, #project_team, #start_date, #project_team_email_id, #project_status)" UpdateCommand="UPDATE [project_details] SET [id]=#id [employee_id] = #employee_id, [project_id] = #project_id, [project_name] = #project_name, [product_name] = #product_name, [client_name] = #client_name, [project_team] = #project_team, [start_date] = #start_date, [project_team_email_id] = #project_team_email_id, [project_status] = #project_status WHERE [id] = #original_id">
<SelectParameters>
<asp:ControlParameter ControlID="employee_id" PropertyName="Text" Name="employee_id" Type="String"></asp:ControlParameter>
<asp:Parameter DefaultValue="individual" Name="project_type" Type="String"></asp:Parameter>
</SelectParameters>
<UpdateParameters>
<asp:Parameter Name="id" Type="String"></asp:Parameter>
<asp:Parameter Name="project_id" Type="String"></asp:Parameter>
<asp:Parameter Name="project_name" Type="String"></asp:Parameter>
<asp:Parameter Name="product_name" Type="String"></asp:Parameter>
<asp:Parameter Name="client_name" Type="String"></asp:Parameter>
<asp:Parameter Name="project_team" Type="String"></asp:Parameter>
<asp:Parameter DbType="DateTime2" Name="start_date"></asp:Parameter>
<asp:Parameter Name="project_team_email_id" Type="String"></asp:Parameter>
</UpdateParameters>
</asp:SqlDataSource>
<%--update project main content--%>
<asp:UpdatePanel runat="server" UpdateMode= "Conditional">
<ContentTemplate>
<asp:GridView ID="project_update_GridView" runat="server" AllowPaging="True" AllowSorting="True" DataSourceID="project_update_DS" CssClass="main-grid-table" HeaderStyle-CssClass="main-grid-header" RowStyle-CssClass="main-grid-row" AutoGenerateColumns="False" DataKeyNames="id" OnRowUpdating="project_update_GridView_RowUpdating" ViewStateMode="Inherit" SortedAscendingHeaderStyle-Wrap="True" EnableViewState="False" EnableModelValidation="False">
<Columns>
<asp:TemplateField HeaderText="<i class='bx bxs-sticker'></i>">
<ItemTemplate>
<input type="checkbox" />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="id" HeaderText="ID" ReadOnly="True" InsertVisible="False" SortExpression="id"></asp:BoundField>
<asp:BoundField DataField="employee_id" HeaderText="Employee ID" SortExpression="employee_id" ReadOnly="true" />
<asp:BoundField DataField="project_id" HeaderText="Project ID" SortExpression="project_id" ReadOnly="true" />
<asp:BoundField DataField="project_name" HeaderText="Project Name" SortExpression="project_name" />
<asp:BoundField DataField="product_name" HeaderText="Product Name" SortExpression="product_name" />
<asp:BoundField DataField="client_name" HeaderText="Client Name" SortExpression="client_name" />
<asp:BoundField DataField="project_team" HeaderText="Team" SortExpression="project_team" />
<asp:BoundField DataField="start_date" HeaderText="Date Started" SortExpression="start_date" />
<asp:BoundField DataField="project_team_email_id" HeaderText="Team Email" SortExpression="project_team_email_id" />
<asp:TemplateField HeaderText="Status" SortExpression="Status" ItemStyle-HorizontalAlign="Left">
<ItemTemplate>
<i class='bx bxs-circle' style='color: #01bf00; display: contents; font-size: x-small;'></i></span><asp:Label ID="status" Style="margin-left: 3px;" runat="server" Text='<%#Bind("project_status")%>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:CommandField HeaderText="Action" ShowSelectButton="false" ShowEditButton="True" EditText="<i class='bx bx-edit'></i>" UpdateText="<i class='bx bx-upload'></i>" CancelText="<i class='bx bx-x-circle'></i>"/>
</Columns>
<EmptyDataTemplate>
<div class="update-default-content" id="update_default_content" runat="server">
<asp:ImageButton runat="server" src="IMG/Create_project_icon.png" ID="update_create_icon" Style="filter: contrast(0.1%);" OnClientClick="javascript:$find('ModalPopupExtender2').hide();$find('create_project_icon').show(); return false;" /><br />
<span>Create Project</span>
</div>
</EmptyDataTemplate>
<HeaderStyle CssClass="main-grid-header" />
<RowStyle CssClass="main-grid-row" />
<SortedDescendingCellStyle />
</asp:GridView>
</ContentTemplate>
</asp:UpdatePanel>
</asp:Panel>
</div>
<asp:GridView ID="dgvCustomers" runat="server" AutoGenerateColumns="False" HorizontalAlign="Center" DataKeyNames="ID" DataSourceID="dsCustomerTickets" BackColor="White" BorderColor="#DEDFDE" BorderStyle="None" BorderWidth="1px" CellPadding="4" ForeColor="Black" GridLines="Vertical" OnRowUpdated="dgvCustomers_RowUpdated">
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:CommandField EditImageUrl="~/svg/edit.png" UpdateImageUrl="~/svg/save.png" CancelImageUrl="~/svg/cancel.png" ButtonType="Image" ShowEditButton="True" />
<asp:BoundField DataField="ID" HeaderText="ID" InsertVisible="False" ReadOnly="True" SortExpression="ID" />
<asp:BoundField DataField="Title" HeaderText="Title" SortExpression="Title" />
<asp:BoundField DataField="Description" HeaderText="Description" SortExpression="Description" />
<asp:BoundField DataField="System" HeaderText="System" SortExpression="System" />
<asp:BoundField DataField="LoggedDate" HeaderText="LoggedDate" SortExpression="LoggedDate" />
<asp:BoundField DataField="ClosedDate" HeaderText="ClosedDate" SortExpression="ClosedDate" />
<asp:BoundField DataField="Resolution" HeaderText="Resolution" SortExpression="Resolution" />
<%--<asp:BoundField DataField="HistoryID" HeaderText="HistoryID" SortExpression="HistoryID" />--%>
<%--<asp:BoundField DataField="Priority" HeaderText="Priority" SortExpression="Priority" />--%>
<asp:BoundField DataField="LoggedBy" HeaderText="LoggedBy" SortExpression="LoggedBy" />
<asp:TemplateField HeaderText="State" SortExpression="State2">
<EditItemTemplate>
<asp:DropDownList ID="ddlstate" runat="server" DataSourceID="SqlDataSource2" DataTextField="State" DataValueField="ID" SelectedValue='<%# Bind("State") %>' AppendDataBoundItems="true">
<asp:ListItem Text="Select a State" Value="" />
</asp:DropDownList>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("State2") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Priority" SortExpression="State3">
<EditItemTemplate>
<asp:DropDownList ID="ddlpriority" runat="server" DataSourceID="SqlDataSource3" DataTextField="Priority" DataValueField="ID" SelectedValue='<%# Bind("Priority") %>' AppendDataBoundItems="true">
<asp:ListItem Text="Select Priority" Value="" />
</asp:DropDownList>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Bind("State3") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<FooterStyle BackColor="#CCCC99" />
<HeaderStyle BackColor="#6B696B" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#F7F7DE" ForeColor="Black" HorizontalAlign="Right" />
<RowStyle BackColor="#F7F7DE" />
<SelectedRowStyle BackColor="#0099ff" Font-Bold="True" ForeColor="White" />
<SortedAscendingCellStyle BackColor="#FBFBF2" />
<SortedAscendingHeaderStyle BackColor="#848384" />
<SortedDescendingCellStyle BackColor="#EAEAD3" />
<SortedDescendingHeaderStyle BackColor="#575357" />
</asp:GridView>
<asp:SqlDataSource ID="dsCustomerTickets" runat="server" ConnectionString="<%$ ConnectionStrings:TicketsSupportConnectionString %>" DeleteCommand="DELETE FROM [Tickets] WHERE [ID] = #ID" InsertCommand="INSERT INTO [Tickets] ([Title], [Description], [System], [LoggedDate], [ClosedDate], [Resolution], [Priority], [HistoryID], [LoggedBy], [State]) VALUES (#Title, #Description, #System, #LoggedDate, #ClosedDate, #Resolution, #Priority, #HistoryID, #LoggedBy, #State)" SelectCommand="SELECT T.ID, T.Title, T.Description, T.System, T.Attachments, T.LoggedDate, T.ClosedDate, T.Resolution, T.Priority, T.LoggedBy, S.State AS State2, p.Priority AS State3 FROM Tickets AS T INNER JOIN State AS S ON T.State = S.ID INNER JOIN Priority AS p ON T.Priority = p.ID WHERE (T.LoggedBy = #LoggedBy)" UpdateCommand="UPDATE Tickets SET Description = #Description, System = #System, ClosedDate = #ClosedDate, Resolution = #Resolution, Priority = #Priority, HistoryID = #HistoryID, State = #State WHERE (ID = #ID)">
<DeleteParameters>
<asp:Parameter Name="ID" Type="Int32" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="Title" Type="String" />
<asp:Parameter Name="Description" Type="String" />
<asp:Parameter Name="System" Type="String" />
<asp:Parameter Name="LoggedDate" Type="DateTime" />
<asp:Parameter Name="ClosedDate" Type="DateTime" />
<asp:Parameter Name="Resolution" Type="String" />
<asp:Parameter Name="Priority" Type="Int32" />
<asp:Parameter Name="HistoryID" Type="Int32" />
<asp:Parameter Name="LoggedBy" Type="String" />
<asp:Parameter Name="State" Type="Int32" />
</InsertParameters>
<SelectParameters>
<asp:QueryStringParameter Name="LoggedBy" QueryStringField="u" />
</SelectParameters>
<UpdateParameters>
<asp:Parameter Name="Description" Type="String" />
<asp:Parameter Name="System" Type="String" />
<asp:Parameter Name="ClosedDate" Type="DateTime" />
<asp:Parameter Name="Resolution" Type="String" />
<asp:Parameter Name="Priority" Type="Int32" />
<asp:Parameter Name="HistoryID" Type="Int32" />
<asp:Parameter Name="State" Type="Int32" />
<asp:Parameter Name="ID" Type="Int32" />
</UpdateParameters>
</asp:SqlDataSource>
<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:TicketsSupportConnectionString %>" SelectCommand="SELECT [ID],[State] FROM [dbo].[State]"></asp:SqlDataSource>
With the above code I get the error constantly.
In SQL if I run the SqlDataSource2 query I get results (ID and State).
I tried Changing my queries and editing my dragged SqlDataSource2 in the query builder.
As soon as I click on the commandfield "EditImageUrl" I get the above error.
Maybe I am looking at my code to long to notice any issues.
I have googled it with no luck looking at stuff like:
I have looked at Here
And the same here, I have bind instead of Eval in the dropdown list.
I also tried changing my sqldatasource to:
Select * from State
Select ID, State from State
Select ID, State from dbo.State
Any help will be appreciated.
Edit and Update
In EditTemplate you fill in aspDropDown from SqlDataSource2 with correct DataTextField="State" DataValueField="ID". But SelectedValue belongs to <asp:SqlDataSource ID="dsCustomerTickets". So you need T.State in SelectCommand to make binding SelectedValue='<%# Bind("State") %>' correct. Also there is no need in Bind in ItemTemplate. Eval("State2") is enough.
And 1st SqlDataSource should be
<asp:SqlDataSource ID="dsCustomerTickets" runat="server"
ConnectionString="<%$ ConnectionStrings:TicketsSupportConnectionString %>"
DeleteCommand="DELETE FROM [Tickets] WHERE [ID] = #ID"
InsertCommand="INSERT INTO [Tickets] (/*removed for shortness*/ [State]) VALUES ( #State2)"
SelectCommand="SELECT /*your list*/ T.State, S.State AS State2, p.Priority AS State3 FROM Tickets AS T INNER JOIN State AS S ON T.State = S.ID INNER JOIN Priority AS p ON T.Priority = p.ID WHERE (T.LoggedBy = #LoggedBy)"
UpdateCommand="UPDATE Tickets SET /*removed for shortness*/ State = #State2 WHERE (ID = #ID)">
<DeleteParameters>
<asp:Parameter Name="ID" Type="Int32" />
</DeleteParameters>
<InsertParameters>
<%--your parameters removed for shortness--%>
<asp:Parameter Name="State" Type="Int32" />
</InsertParameters>
<SelectParameters>
<asp:QueryStringParameter Name="LoggedBy" QueryStringField="u" />
</SelectParameters>
<UpdateParameters>
<%--your parameters removed for shortness--%>
<asp:Parameter Name="State" Type="Int32" />
<asp:Parameter Name="ID" Type="Int32" />
</UpdateParameters>
</asp:SqlDataSource>
I've created a DetailsView that displays data based on a selected item from a GridView. When the DetailsView is under Edit Mode, it displays dropdownlists that contain data from a SQL databind. The data displays in the dropdownlist without issue, but fails to update. All other fields succeed.
The data is bound to the drop down via OnDataBound.
The idea is to populate the SelectedValue with the current data, and populate what it can be changed to. This works without issue. It simply fails to update.
I believe it has to do with syncing the control with the "an" parameter, but am at a loss at how to do so.
Front End Code pertaining to the issue:
<asp:DetailsView ID="userDetails" runat="server"
Height="50px"
Width="400px"
AutoGenerateRows="False"
CellPadding="4"
DataKeyNames="id"
DataSourceID="detailsSqlDataSource"
ForeColor="#333333"
GridLines="None"
OnDataBound="userDetails_ItemEdit">
<AlternatingRowStyle BackColor="White" />
<CommandRowStyle BackColor="#D1DDF1" Font-Bold="True" />
<EditRowStyle BackColor="#2461BF" />
<FieldHeaderStyle BackColor="#DEE8F5" Font-Bold="True" width="125px"/>
<Fields>
<asp:BoundField DataField="id" HeaderText="id" InsertVisible="False" ReadOnly="True" SortExpression="id" />
<asp:BoundField DataField="first_name" HeaderText="First Name" SortExpression="first_name" />
<asp:BoundField DataField="last_name" HeaderText="Last Name" SortExpression="last_name" />
<asp:BoundField DataField="user_name" HeaderText="User Name" SortExpression="user_name" />
<asp:TemplateField HeaderText="T" SortExpression="t">
<EditItemTemplate>
<asp:DropDownList ID="tEditDD" runat="server" SelectedValue='<%# Bind("t") %>'>
<asp:ListItem Value="t1" Text="t1"></asp:ListItem>
<asp:ListItem Value="t2" Text="t2"></asp:ListItem>
<asp:ListItem Value="t3" Text="t3"></asp:ListItem>
</asp:DropDownList>
</EditItemTemplate>
<InsertItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("t") %>'></asp:TextBox>
</InsertItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("t") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="P" SortExpression="p">
<EditItemTemplate>
<asp:DropDownList ID="pEditDD" runat="server" SelectedValue='<%# Bind("p") %>'>
<asp:ListItem Value="As" Text="As"></asp:ListItem>
<asp:ListItem Value="An" Text="An"></asp:ListItem>
<asp:ListItem Value="Su" Text="Su"></asp:ListItem>
<asp:ListItem Value="Ad" Text="Ad"></asp:ListItem>
</asp:DropDownList>
</EditItemTemplate>
<InsertItemTemplate>
<asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("p") %>'></asp:TextBox>
</InsertItemTemplate>
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Bind("p") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="An" SortExpression="an">
<EditItemTemplate>
<asp:DropDownList ID="anEditDD" runat="server">
</asp:DropDownList>
</EditItemTemplate>
<InsertItemTemplate>
<asp:TextBox ID="TextBox3" runat="server" Text='<%# Bind("an") %>'></asp:TextBox>
</InsertItemTemplate>
<ItemTemplate>
<asp:Label ID="Label3" runat="server" Text='<%# Bind("an") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Su" SortExpression="su">
<EditItemTemplate>
<asp:DropDownList ID="suEditDD" runat="server" >
</asp:DropDownList>
</EditItemTemplate>
<InsertItemTemplate>
<asp:TextBox ID="TextBox4" runat="server" Text='<%# Bind("su") %>'></asp:TextBox>
</InsertItemTemplate>
<ItemTemplate>
<asp:Label ID="Label4" runat="server" Text='<%# Bind("su") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="email" HeaderText="E-Mail" SortExpression="email" />
<asp:TemplateField HeaderText="AL" SortExpression="al">
<EditItemTemplate>
<asp:DropDownList ID="alEditDD" runat="server" SelectedValue='<%# Bind("al") %>'>
<asp:ListItem Value="As" Text="As"></asp:ListItem>
<asp:ListItem Value="An" Text="An"></asp:ListItem>
<asp:ListItem Value="Su" Text="Su"></asp:ListItem>
<asp:ListItem Value="Ad" Text="Ad"></asp:ListItem>
</asp:DropDownList>
</EditItemTemplate>
<InsertItemTemplate>
<asp:DropDownList ID="alInsertDD" runat="server" SelectedValue='<%# Bind("al") %>'>
<asp:ListItem></asp:ListItem>
<asp:ListItem Value="As" Text="As"></asp:ListItem>
<asp:ListItem Value="An" Text="An"></asp:ListItem>
<asp:ListItem Value="Su" Text="Su"></asp:ListItem>
<asp:ListItem Value="Ad" Text="Ad"></asp:ListItem>
</asp:DropDownList>
</InsertItemTemplate>
<ItemTemplate>
<asp:Label ID="Label5" runat="server" Text='<%# Bind("al") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:CommandField ShowDeleteButton="True" ShowEditButton="True" ShowInsertButton="True" />
</Fields>
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#EFF3FB" />
</asp:DetailsView>
<asp:SqlDataSource ID="detailsSqlDataSource" runat="server"
ConflictDetection="CompareAllValues"
ConnectionString="<%$ ConnectionStrings:CPConnectionString %>"
UpdateCommand="UPDATE [users] SET [first_name] = #first_name, [last_name] = #last_name, [user_name] = #user_name, [t] = #t, [p] = #p, [an] = #an, [su] = #su, [email] = #email, [al] = #al WHERE [id] = #original_id">
<SelectParameters>
<asp:ControlParameter ControlID="usersGrid" Name="id" PropertyName="SelectedValue" Type="Int32" />
</SelectParameters>
<UpdateParameters>
<asp:Parameter Name="first_name" Type="String" />
<asp:Parameter Name="last_name" Type="String" />
<asp:Parameter Name="user_name" Type="String" />
<asp:Parameter Name="t" Type="String" />
<asp:Parameter Name="p" Type="String" />
<asp:Parameter Name="an" Type="String" />
<asp:Parameter Name="su" Type="String" />
<asp:Parameter Name="email" Type="String" />
<asp:Parameter Name="al" Type="String" />
<asp:Parameter Name="original_id" Type="Int32" />
<asp:Parameter Name="original_first_name" Type="String" />
<asp:Parameter Name="original_last_name" Type="String" />
<asp:Parameter Name="original_user_name" Type="String" />
<asp:Parameter Name="original_t" Type="String" />
<asp:Parameter Name="original_p" Type="String" />
<asp:Parameter Name="original_an" Type="String" />
<asp:Parameter Name="original_su" Type="String" />
<asp:Parameter Name="original_email" Type="String" />
<asp:Parameter Name="original_al" Type="String" />
</UpdateParameters>
</asp:SqlDataSource>
Code Behind:
protected void userDetails_ItemEdit(object sender, EventArgs e)
{
if (userDetails.CurrentMode == DetailsViewMode.Edit)
{
AnDD();
}
}
protected void AnDD()
{
DropDownList anEditDD = userDetails.FindControl("anEditDD") as DropDownList;
string userName = ((TextBox)userDetails.Rows[3].Cells[1].Controls[0]).Text;
string conStr = System.Configuration.ConfigurationManager.ConnectionStrings["CPConnectionString"].ConnectionString;
SqlConnection con = new SqlConnection(conStr);
con.Open();
string currentAnSqlSelect = "SELECT an FROM users WHERE user_name='" + userName + "'";
SqlDataReader currentReader;
SqlCommand ccmd = new SqlCommand(currentAnSqlSelect, con);
currentReader = ccmd.ExecuteReader();
while (currentReader.Read())
{
ListItem currentList = new ListItem();
currentList.Text = currentReader["an"].ToString();
errorLBL.Text = currentReader["an"].ToString();
anEditDD.Items.Add(currentList);
}
currentReader.Close();
string anSqlSelect = "SELECT first_name, last_name FROM users WHERE position='An'";
SqlDataReader anReader;
SqlCommand cmd = new SqlCommand(anSqlSelect, con);
anReader = cmd.ExecuteReader();
while (anReader.Read())
{
ListItem anList = new ListItem();
anList.Text = anReader["first_name"].ToString() + " " + anReader["last_name"].ToString();
anEditDD.Items.Add(anList);
}
anReader.Close();
con.Close();
anEditDD.Items.Add("N/A");
anEditDD.DataBind();
anEditDD.SelectedIndex = 0;
}
Your update command appears to be part of the details view, and not part of any ObjectDataSource. Can you confirm your markup above is correct?
Edit
In your UpdateParameters group, you aren't getting the values from the controls. Try doing the following:
<UpdateParameters>
<asp:Parameter />
...snip
<asp:ControlParameter Name="an" ControlID="idOfWhateverControlHasTheUserSetValue" Type="String" />
...snip
</UpdateParameters>
I took your advice and did a little research about using the ControlParameter.
The fix was adding the following to the Update Parameters, and removing the auto-populated parameters for 'an'. Thanks for the help, Nick.
<asp:ControlParameter Name="an" ControlID="userDetails$anEditDD" PropertyName="SelectedValue" Type="String" />
I have a page with a details view and a grid view (each with their own data source. I can't figure out why the update says it's successful but don't update the table. the details view works fine. The grid view is only suppose to show data related to what's in the details view. If I hard code the values in the source it works but when I change it back it blows up. here's my code
<asp:SqlDataSource OnUpdated="dsCar_Updated" ID="dsCar" runat="server"
ConnectionString="<%$ ConnectionStrings:VehicalList %>"
ProviderName="<%$ ConnectionStrings:VehicalList.ProviderName %>"
SelectCommand="SELECT Car.* FROM Car WHERE (VIN = ?)"
UpdateCommand="UPDATE Car SET [Branch ID] = ?, [State Registration] = ?, [License Plate] = ?, Color = ?, Model = ?, [Car Year] = ?, [Plate Expiration] = ? WHERE (VIN = ?)">
<SelectParameters>
<asp:QueryStringParameter Name="?" QueryStringField="VIN" />
</SelectParameters>
</asp:SqlDataSource>
<asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False"
DataSourceID="dsCar" Height="50px" Width="265px" CellPadding="4"
ForeColor="#333333" GridLines="None" DataKeyNames="VIN" DefaultMode="Edit">
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
<CommandRowStyle BackColor="#E2DED6" Font-Bold="True" />
<EditRowStyle BackColor="#999999" />
<FieldHeaderStyle BackColor="#E9ECF1" Font-Bold="True" />
<Fields>
<asp:BoundField DataField="VIN" HeaderText="VIN" ReadOnly="True"
SortExpression="VIN" />
<asp:TemplateField HeaderText="Branch Name" SortExpression="Branch ID">
<EditItemTemplate>
<asp:SqlDataSource ID="SqlDataSource2" runat="server"
ConnectionString="<%$ ConnectionStrings:VehicalList %>"
ProviderName="<%$ ConnectionStrings:VehicalList.ProviderName %>"
SelectCommand="SELECT * FROM [Branch]"></asp:SqlDataSource>
<asp:DropDownList ID="DropDownList1" runat="server"
DataSourceID="SqlDataSource2" DataTextField="Branch Name"
DataValueField="Branch ID" SelectedValue='<%# Bind("[Branch ID]") %>'>
</asp:DropDownList>
</EditItemTemplate>
<InsertItemTemplate>
<asp:SqlDataSource ID="SqlDataSource3" runat="server"
ConnectionString="<%$ ConnectionStrings:VehicalList %>"
ProviderName="<%$ ConnectionStrings:VehicalList.ProviderName %>"
SelectCommand="SELECT * FROM [Branch]"></asp:SqlDataSource>
<asp:DropDownList ID="DropDownList1" runat="server"
DataSourceID="SqlDataSource3" DataTextField="Branch Name"
DataValueField="Branch ID" SelectedValue='<%# Bind("[Branch ID]") %>'>
</asp:DropDownList>
</InsertItemTemplate>
<ItemTemplate>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:VehicalList %>"
ProviderName="<%$ ConnectionStrings:VehicalList.ProviderName %>"
SelectCommand="SELECT * FROM [Branch]"></asp:SqlDataSource>
<asp:DropDownList ID="DropDownList1" runat="server"
DataSourceID="SqlDataSource1" DataTextField="Branch Name"
DataValueField="Branch ID" Enabled="False" SelectedValue='<%# Bind("[Branch ID]") %>'>
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="State Registration" HeaderText="State Registration"
SortExpression="State Registration" />
<asp:BoundField DataField="License Plate" HeaderText="License Plate"
SortExpression="License Plate" />
<asp:BoundField DataField="Color" HeaderText="Color" SortExpression="Color" />
<asp:TemplateField HeaderText="Model" SortExpression="Model">
<EditItemTemplate>
<asp:SqlDataSource ID="SqlDataSource4" runat="server"
ConnectionString="<%$ ConnectionStrings:VehicalList %>"
ProviderName="<%$ ConnectionStrings:VehicalList.ProviderName %>"
SelectCommand="SELECT * FROM [Model]"></asp:SqlDataSource>
<asp:DropDownList ID="DropDownList2" runat="server"
DataSourceID="SqlDataSource4" DataTextField="Model Name"
DataValueField="ModelID" SelectedValue='<%# Bind("Model") %>'>
</asp:DropDownList>
</EditItemTemplate>
<InsertItemTemplate>
<asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("Model") %>'></asp:TextBox>
</InsertItemTemplate>
<ItemTemplate>
<asp:SqlDataSource ID="SqlDataSource4" runat="server"
ConnectionString="<%$ ConnectionStrings:VehicalList %>"
ProviderName="<%$ ConnectionStrings:VehicalList.ProviderName %>"
SelectCommand="SELECT * FROM [Model]"></asp:SqlDataSource>
<asp:DropDownList ID="DropDownList2" runat="server"
DataSourceID="SqlDataSource4" DataTextField="Model Name"
DataValueField="ModelID" SelectedValue='<%# Bind("Model") %>'
Enabled="False">
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="Car Year" HeaderText="Car Year"
SortExpression="Car Year" />
<asp:TemplateField HeaderText="Plate Expiration"
SortExpression="Plate Expiration">
<EditItemTemplate>
<asp:SqlDataSource ID="SqlDataSource5" runat="server"
ConnectionString="<%$ ConnectionStrings:VehicalList %>"
ProviderName="<%$ ConnectionStrings:VehicalList.ProviderName %>"
SelectCommand="SELECT * FROM [Car]"></asp:SqlDataSource>
<asp:Calendar ID="Calendar1" runat="server"
onselectionchanged="Calendar1_SelectionChanged"
VisibleDate='<%# Eval("[Plate Expiration]") %>'
SelectedDate='<%# Bind("[Plate Expiration]") %>'></asp:Calendar>
<asp:TextBox ID="txtDateEdit" runat="server"
Text='<%# Bind("[Plate Expiration]") %>'></asp:TextBox>
<br />
</EditItemTemplate>
<InsertItemTemplate>
<asp:Calendar ID="Calendar1" runat="server"
onselectionchanged="Calendar1_SelectionChanged"
VisibleDate='<%# Eval("[Plate Expiration]") %>'></asp:Calendar>
<asp:TextBox ID="TextBox1" runat="server"
Text='<%# Bind("[Plate Expiration]") %>' Visible="false"></asp:TextBox>
</InsertItemTemplate>
<ItemTemplate>
<br />
<asp:Label ID="Label1" runat="server" Text='<%# Eval("[Plate Expiration]") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:CommandField ShowEditButton="True" />
</Fields>
</asp:DetailsView>
<asp:SqlDataSource OnUpdated="dsMaintance_Updated" ID="dsMaintance" runat="server"
ConnectionString="<%$ ConnectionStrings:VehicalList %>"
DeleteCommand="DELETE FROM [Maintenance] WHERE [MainteanceID] = ?"
InsertCommand="INSERT INTO [Maintenance] ([MainteanceID], [VIN], [Procedure ID], [Date]) VALUES (?, ?, ?, ?)"
ProviderName="<%$ ConnectionStrings:VehicalList.ProviderName %>"
SelectCommand="SELECT MainteanceID, VIN, [Procedure ID], [Date] FROM Maintenance WHERE (VIN = ?)"
UpdateCommand="UPDATE Maintenance SET [Procedure ID] = ?, [Date] = ? WHERE (MainteanceID = ?)">
<DeleteParameters>
<asp:Parameter Name="MainteanceID" Type="Int32" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="MainteanceID" Type="Int32" />
<asp:Parameter Name="VIN" Type="String" />
<asp:Parameter Name="Procedure_ID" Type="Int32" />
<asp:Parameter Name="Date" Type="DateTime" />
</InsertParameters>
<SelectParameters>
<asp:QueryStringParameter Name="VIN" QueryStringField="VIN" Type="String" />
</SelectParameters>
<UpdateParameters>
<asp:Parameter Name="MainteanceID" Type="Int32" />
<asp:Parameter Name="VIN" Type="String" />
<asp:Parameter Name="Procedure_ID" Type="Int32" />
<asp:Parameter Name="Date" Type="DateTime" />
</UpdateParameters>
</asp:SqlDataSource>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataKeyNames="MainteanceID" DataSourceID="dsMaintance" BackColor="White"
BorderColor="White" BorderStyle="Ridge" BorderWidth="2px" CellPadding="3"
CellSpacing="1" GridLines="None">
<Columns>
<asp:CommandField ShowDeleteButton="True" ShowEditButton="True" />
<asp:BoundField DataField="MainteanceID" HeaderText="MainteanceID"
InsertVisible="False" ReadOnly="True" SortExpression="MainteanceID" />
<asp:BoundField DataField="VIN" HeaderText="VIN" SortExpression="VIN" />
<asp:BoundField DataField="Procedure ID" HeaderText="Procedure ID"
SortExpression="Procedure ID" />
<asp:BoundField DataField="Date" HeaderText="Date" SortExpression="Date" />
</Columns>
</asp:GridView>
You should pass the proper parameters to the UpdateParameters section. It looks like you have a copy-paste problem (maybe you copied the section from the InsertParameters section). Your UPDATE statement needs only 3 parameters.
<asp:SqlDataSource OnUpdated="dsMaintance_Updated" ID="dsMaintance" runat="server"
ConnectionString="<%$ ConnectionStrings:VehicalList %>"
DeleteCommand="DELETE FROM [Maintenance] WHERE [MainteanceID] = ?"
InsertCommand="INSERT INTO [Maintenance] ([MainteanceID], [VIN], [Procedure ID], [Date]) VALUES (?, ?, ?, ?)"
ProviderName="<%$ ConnectionStrings:VehicalList.ProviderName %>"
SelectCommand="SELECT MainteanceID, VIN, [Procedure ID], [Date] FROM Maintenance WHERE (VIN = ?)"
UpdateCommand="UPDATE Maintenance SET [Procedure ID] = ?, [Date] = ? WHERE (MainteanceID = ?)">
<DeleteParameters>
<asp:Parameter Name="MainteanceID" Type="Int32" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="MainteanceID" Type="Int32" />
<asp:Parameter Name="VIN" Type="String" />
<asp:Parameter Name="Procedure_ID" Type="Int32" />
<asp:Parameter Name="Date" Type="DateTime" />
</InsertParameters>
<SelectParameters>
<asp:QueryStringParameter Name="VIN" QueryStringField="VIN" Type="String" />
</SelectParameters>
<UpdateParameters>
<%--<asp:Parameter Name="MainteanceID" Type="Int32" />--%>
<%--<asp:Parameter Name="VIN" Type="String" />--%>
<asp:Parameter Name="Procedure_ID" Type="Int32" />
<asp:Parameter Name="Date" Type="DateTime" />
</UpdateParameters>
</asp:SqlDataSource>
I was following this so far everything is fine with a textbox but when try to modify it to checkbox it gives an error: Unable to cast object of type 'System.Web.UI.WebControls.TextBox' to type 'System.Web.UI.WebControls.CheckBox'.
Its working when I use TextBox but how can I make all the CheckBox editable in bulk updates?
Here's the sample code behind
private bool tableCopied = false;
private DataTable originalDataTable;
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
if (!tableCopied)
{
originalDataTable = ((DataRowView)e.Row.DataItem).Row.Table.Copy();
ViewState["originalValueTable"] = originalDataTable;
tableCopied = true;
}
}
protected void UpdateButton_Click(object sender, EventArgs e)
{
originalDataTable = (DataTable)ViewState["originalValueTable"];
foreach (GridViewRow r in GridView1.Rows)
if (IsRowModified(r))
{
GridView1.UpdateRow(r.RowIndex, false);
}
tableCopied = false;
GridView1.DataBind();
}
protected bool IsRowModified(GridViewRow r)
{
int currentID;
string currentreservedate;
string currentisapproved;
currentID = Convert.ToInt32(GridView1.DataKeys[0].Value);
currentreservedate = ((TextBox)r.FindControl("reservedateTextBox")).Text;
currentisapproved = ((CheckBox)r.FindControl("isapprovedCheckBox")).Text;
DataRow row = originalDataTable.Select(String.Format("reservationid = {0}", currentID))[0];
if (!currentreservedate.Equals(row["reservedate"].ToString()))
if (!currentisapproved.Equals(row["isapproved"].ToString()))
{
return true;
}
return false;
}
}
}
Here's the aspx markup
Pending Reservation<br />
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:LibrarySystemConnectionString %>"
SelectCommand="SELECT dbo.BookReservation.reservationid, dbo.BookReservation.bookid, dbo.BookReservation.EmployeeID, dbo.BookReservation.reservedate, dbo.BookReservation.isapproved, dbo.BookReservation.reschedule, dbo.BookReservation.isdeleted, dbo.TblBooks.booktitle FROM dbo.BookReservation INNER JOIN dbo.TblBooks ON dbo.BookReservation.bookid = dbo.TblBooks.bookid"
DeleteCommand="DELETE FROM [BookReservation] WHERE [reservationid] = #reservationid"
InsertCommand="INSERT INTO [BookReservation] ([bookid], [EmployeeID], [reservedate], [isapproved], [reschedule], [isdeleted]) VALUES (#bookid, #EmployeeID, #reservedate, #isapproved, #reschedule, #isdeleted)"
UpdateCommand="UPDATE [BookReservation] SET [bookid] = #bookid, [EmployeeID] = #EmployeeID, [reservedate] = #reservedate, [isapproved] = #isapproved, [reschedule] = #reschedule, [isdeleted] = #isdeleted WHERE [reservationid] = #reservationid">
<DeleteParameters>
<asp:Parameter Name="reservationid" Type="Int32" />
</DeleteParameters>
<UpdateParameters>
<asp:Parameter Name="bookid" Type="Int64" />
<asp:Parameter Name="EmployeeID" Type="String" />
<asp:Parameter Name="reservedate" Type="DateTime" />
<asp:Parameter Name="isapproved" Type="Boolean" />
<asp:Parameter Name="reschedule" Type="Boolean" />
<asp:Parameter Name="isdeleted" Type="Boolean" />
<asp:Parameter Name="reservationid" Type="Int32" />
</UpdateParameters>
<InsertParameters>
<asp:Parameter Name="bookid" Type="Int64" />
<asp:Parameter Name="EmployeeID" Type="String" />
<asp:Parameter Name="reservedate" Type="DateTime" />
<asp:Parameter Name="isapproved" Type="Boolean" />
<asp:Parameter Name="reschedule" Type="Boolean" />
<asp:Parameter Name="isdeleted" Type="Boolean" />
</InsertParameters>
</asp:SqlDataSource>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" AllowPaging="true" AllowSorting="true"
DataKeyNames="reservationid, bookid, EmployeeID, reservedate " DataSourceID="SqlDataSource1" OnRowDataBound="GridView1_RowDataBound" >
<Columns>
<asp:BoundField DataField="reservationid" HeaderText="reservationid"
InsertVisible="False" ReadOnly="True"
SortExpression="reservationid" Visible="False" />
<asp:BoundField DataField="bookid" HeaderText="bookid"
SortExpression="bookid" Visible="False" />
<asp:BoundField DataField="booktitle" HeaderText="Title"
SortExpression="booktitle" />
<asp:BoundField DataField="EmployeeID" HeaderText="Reserved by"
SortExpression="EmployeeID" />
<%--<asp:BoundField DataField="reservedate" HeaderText="Date reserved"
SortExpression="reservedate" />--%>
<asp:TemplateField HeaderText="Reserve Date"
SortExpression="reservedate">
<EditItemTemplate>
<asp:TextBox ID="reservedateTextBox" runat="server" Text='<%# Bind("reservedate") %>'>
</asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:TextBox ID="reservedateTextBox" runat="server" Text='<%# Bind("reservedate") %>'>
</asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<%--<asp:CheckBoxField DataField="isapproved" HeaderText="Approved"
SortExpression="isapproved" />--%>
<asp:TemplateField HeaderText="Apprvoed"
SortExpression="isapproved">
<EditItemTemplate>
<asp:TextBox ID="isapprovedCheckBox" runat="server" Text='<%# Bind("isapproved") %>'>
</asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:TextBox ID="isapprovedCheckBox" runat="server" Text='<%# Bind("isapproved") %>'>
</asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:CheckBoxField DataField="reschedule" HeaderText="Reschedule"
SortExpression="reschedule" />
<asp:CheckBoxField DataField="isdeleted" HeaderText="Deleted"
SortExpression="isdeleted" />
</Columns>
</asp:GridView>
<br />
<br />
<asp:Button ID="UpdateButton" runat="server" Text="Update" OnClick="UpdateButton_Click" />
<br />
Help would be much appreciated! Thanks in advance!
I think that to answer this question, the contents of the aspx file are required, but I'll try to help. More than likely the element in your form, isapprovedCheckBox, is still set to the the tag asp:Text. As a result the system can't convert the textbox to a checkbox.
Could you include your aspx content as well?