Nested DetailsView insert method's parameters - c#

I have DetailsView nested in GridView, and I can't figure out how to pass values(like ID of item in GridView and value from session) to parameters for insert method.
<asp:DetailsView ID="DetailsViewPostLikes" runat="server"
AutoGenerateRows="false" DataSourceID="odsPostLikes"
DataKeyNames="id" GridLines="None">
<Fields>
<asp:CommandField ShowInsertButton="true" InsertText="Like" newtext="Like" />
<asp:TemplateField HeaderText="" SortExpression="Nickname">
<ItemTemplate>
<asp:Label id="nicknamelikesCount" runat="server" Text='<%# Bind("LikeCount") %>'></asp:Label> people likes this.
</ItemTemplate>
</asp:TemplateField>
</Fields>
</asp:DetailsView>
<asp:ObjectDataSource ID="odsPostLikes" runat="server"
TypeName="SocWebApp.Database.PostLikeTable"
SelectMethod="Select" InsertMethod="Insert" UpdateMethod="Update">
<SelectParameters>
<asp:Parameter Name="postId" Type="Int32" />
</SelectParameters>
<InsertParameters>
<asp:Parameter Name="postId" Type="Int32" />
<asp:SessionParameter Name="userId" SessionField="User_id" Type="Int32" />
</InsertParameters>
</asp:ObjectDataSource>
I've tried to do this same way as for select parameter like this:
protected void posts_ItemDatabound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)//(GridView)e.Row.FindControl("odsComments") != null)
{
ObjectDataSource s1 = (ObjectDataSource)e.Row.FindControl("odsComments");
s1.SelectParameters["postId"].DefaultValue = DataBinder.Eval(e.Row.DataItem, "Id").ToString();
ObjectDataSource s2 = (ObjectDataSource)e.Row.FindControl("odsPostLikes");
s2.InsertParameters["postId"].DefaultValue = DataBinder.Eval(e.Row.DataItem, "Id").ToString();
ObjectDataSource s3 = (ObjectDataSource)e.Row.FindControl("odsPostLikes");
s3.InsertParameters["userId"].DefaultValue = Session["User_id"].ToString();
}
}
but only userId parameter value is set(from Session), postId is always 0.
What is the proper solution?
Thank you.

I've found the solution:
<asp:DetailsView ID="DetailsViewPostLikes" runat="server"
AutoGenerateRows="false" DataSourceID="odsPostLikes"
DataKeyNames="id" GridLines="None" OnDataBound="postLikeInsert_DataBound" OnItemCommand="postLikeInsert_ItemCommand">
<Fields>
<asp:CommandField ShowInsertButton="false" InsertText="Like" newtext="Like" />
<asp:TemplateField HeaderText="" SortExpression="Nickname">
<ItemTemplate>
<asp:LinkButton ID="Like" runat="server" CommandName="Insert" Text="Like" />
<asp:Label id="likesCount" runat="server" Text='<%# Bind("LikeCount") %>'></asp:Label> people likes this.
</ItemTemplate>
</asp:TemplateField>
</Fields>
</asp:DetailsView>
<asp:ObjectDataSource ID="odsPostLikes" runat="server"
TypeName="SocWebApp.Database.PostLikeTable"
SelectMethod="Select" InsertMethod="Insert" UpdateMethod="Update">
<SelectParameters>
<asp:Parameter Name="postId" Type="Int32" />
</SelectParameters>
<InsertParameters>
<asp:Parameter Name="postId" Type="Int32" />
<asp:SessionParameter Name="userId" SessionField="User_id" Type="Int32" />
</InsertParameters>
</asp:ObjectDataSource>
code-behind:
protected void postLikeInsert_DataBound(object sender, EventArgs e)
{
DetailsView d = (DetailsView)sender;
GridViewRow row = (GridViewRow)d.NamingContainer;
int idx = row.RowIndex;
GridView grid = (GridView)row.NamingContainer;
string strGoalIndicatorID = grid.DataKeys[idx]["id"].ToString();
LinkButton b = (LinkButton)d.FindControl("Like");
b.CommandArgument = strGoalIndicatorID;
}
protected void postLikeInsert_ItemCommand(object sender, DetailsViewCommandEventArgs e)
{
if (e.CommandName == "Insert")
{
DetailsView d = (DetailsView)sender;
d.ChangeMode(DetailsViewMode.Insert);
ObjectDataSource o = (ObjectDataSource)d.NamingContainer.FindControl("odsPostLikes");
o.InsertParameters["postId"].DefaultValue = e.CommandArgument.ToString();
}
}
when data bound, it will find the button and set his command argument to id item of parent gridview, then after hitting the button, insert parameter is set based on that command argument

Related

ASP.NET SQLDataSource SelectParameters not set correctly

I have an ASP.NET web form coded like this:
<asp:TextBox
ClientIDMode="Static"
ID="_txtExitDate"
runat="server"
EnableViewState="true" />
<asp:TextBox
ClientIDMode="Static"
ID="_txtEnterDate"
runat="server"
EnableViewState="true" />
<asp:Button
runat="server"
ClientIDMode="Static"
ID="_btnSearch"
Text="Search"
OnClick="_btnSearch_Click" />
<asp:GridView
ID="_gvRecords"
runat="server"
DataSourceID="_sdsRecords"
DataKeyNames="total_records"
CellPadding="0"
CellSpacing="0"
ShowHeader="true"
ShowFooter="true"
PageSize="20"
SelectedIndex="0"
Width="100%"
BorderStyle="None"
GridLines="Horizontal"
AutoGenerateColumns="false"
AllowSorting="true"
AllowPaging="true"
EmptyDataText="No records."
OnPageIndexChanging="_gvRecords_PageIndexChanging"
OnSorting="_gvRecords_Sorting" >
<SelectedRowStyle CssClass="SelRow" />
<HeaderStyle CssClass="GridHeader" />
<AlternatingRowStyle CssClass="AltRow" BackColor="#F7F5E9" />
<Columns>
<asp:BoundField DataField="region" HeaderText="Region" SortExpression="region" />
<asp:BoundField DataField="total_records" HeaderText="Records" SortExpression="total_records" />
</Columns>
</asp:GridView>
Of course these are only the relevant tags the layout is managed by other code that's not important.
The form include a SQLDataSource defined like this:
<asp:SqlDataSource
runat="server"
ConnectionString="<%$ ConnectionStrings:db %>"
ProviderName="<%$ ConnectionStrings:db.ProviderName %>"
ID="_sdsRecords"
OnSelecting="_sdsRecords_Selecting"
SelectCommand ="
SELECT
COUNT(DISTINCT(records.id)) AS total_records,
tab_cities.city_region AS region
FROM
records
INNER JOIN
tab_A ON records.id_subject = tab_A.id
INNER JOIN
tab_cities ON tab_cities.city_province_code = tab_A.province
WHERE
(records.mode = 'S')
AND (records.status = 'C')
AND (records.delete_date IS NULL)
AND (records.exit_date >= #exit)
AND (records.enter_date <= #enter)
GROUP BY
tab_cities.city_region
ORDER BY
total_records DESC">
<SelectParameters>
<asp:Parameter Direction="Input" DbType="DateTime" Name="exit" />
<asp:Parameter Direction="Input" DbType="DateTime" Name="enter" />
</SelectParameters>
</asp:SqlDataSource>
The codebehind is something like this:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack) {
DateTime date = DateTime.Now;
var firstDayOfMonth = new DateTime(date.Year, date.Month-1, 1);
var lastDayOfMonth = firstDayOfMonth.AddMonths(1).AddDays(-1);
_txtExitDate.Text = firstDayOfMonth.ToShortDateString();
_txtEnterDate.Text = lastDayOfMonth.ToShortDateString();
}
}
protected void _btnSearch_Click(object sender, EventArgs e)
{
_sdsRecords.Select(DataSourceSelectArguments.Empty);
}
protected void _sdsNoleggi_Selecting(object sender, SqlDataSourceSelectingEventArgs e)
{
DateTime _exit = DateTime.Parse(_txtExitDate.Text.Trim());
DateTime _enter = DateTime.Parse(_txtEnterDate.Text.Trim());
e.Command.Parameters["exit"].Value = _exit ;
e.Command.Parameters["enter"].Value = _enter ;
}
The form seems to work at startup i.e. the query returns the number of rows I'm expecting but if I try to change the value of _txtExitDate and _txtEnterDate and click on search button nothing changes.
_sdsNoleggi_Selecting() is triggered and command parameters are set correctly.
Another issue I cannot unserstand is why if I change <asp:Parameter /> with <asp:ControlParameter /> like this:
<SelectParameters>
<asp:ControlParameter DbType="DateTime" Name="exit" ControlID="_txtExitDate" PropertyName="Text" ConvertEmptyStringToNull="true" />
<asp:ControlParameter DbType="DateTime" Name="enter" ControlID="_txtEnterDate" PropertyName="Text" ConvertEmptyStringToNull="true" />
</SelectParameters>
parameters are not set correctly and then the whole query doesn't return any record (_sdsRecords_Selecting() event handler is removed in such case).
---- LATE UPDATE ----
As stated below the site this page come from is fully coded this way. Changing the paradigm of the whole thing is not an option.

Do not bind drop down list if selected value not found in list of items

How do I tell SelectedValue='<%# Bind("AccID") %>' do not perform the binding if AccID is not in the list of items?
<EditItemTemplate>
<asp:ObjectDataSource ID="ObjectDataSourceAccount" runat="server" SelectMethod="GetUsableAccountByUser"
TypeName="t_MT_AccCode" OnSelected="ObjectDataSourceAccount_Selected" OnSelecting="ObjectDataSourceAccount_Selecting">
<SelectParameters>
<asp:Parameter Name="companyCode" />
<asp:Parameter Name="departmentCode" />
<asp:Parameter Name="badgeNumber" />
<asp:Parameter Name="userRole" />
</SelectParameters>
</asp:ObjectDataSource>
<asp:DropDownList ID="DropDownListAccount" runat="server" DataSourceID="ObjectDataSourceAccount"
DataTextField="accountDesc" DataValueField="id"
SelectedValue='<%# Bind("AccID") %>'
ondatabinding="DropDownListAccount_DataBinding"
ondatabound="DropDownListAccount_DataBound">
</asp:DropDownList>
</EditItemTemplate>
This is how I solved this issue.
But I was hoping I can solve it through SelectedValue='<%# Bind("AccID") %>' instead.
protected void DropDownListAccount_DataBound(object sender, EventArgs e)
{
DropDownList dropDownListAccount = (DropDownList)sender;
DataRowView currentDataRowView = (DataRowView)((GridViewRow)dropDownListAccount.Parent.Parent).DataItem;
int currentRowDataKeyItemId = int.Parse(currentDataRowView["ID"].ToString());
int accountId = t_MT_MTItem.GetAccountIdByItemId(currentRowDataKeyItemId);
dropDownListAccount.SelectedValue = accountId.ToString();
}

Stored procedure expects parameter that was not supplied

I have a SqlDataSource connected to a GridView and I am trying to get the edit working correctly, but with everything I try I still get that parameters are not supplied.
I have tried naming the parameters with and without the '#', it seems to make no difference. As you can see in the below image, the update parameters exist and even have values!
Example image:
ASPX markup:
<asp:GridView runat="server" ID="JobGV" DataSourceID="JobApprovalsDS"
AutoGenerateColumns="False" AutoGenerateEditButton="true"
OnRowCommand="JobGV_OnRowCommand" OnRowUpdating="JobGV_OnRowUpdating">
<Columns>
<asp:BoundField HeaderText="Function" DataField="FunDesc" ReadOnly="true"/>
<asp:BoundField HeaderText="Employee" DataField="EmpName" ReadOnly="true"/>
<asp:TemplateField>
<EditItemTemplate>
<asp:DropDownList runat="server" ID="ddlEmps" SelectedValue='<%# Eval("appEmpID")%>' DataSourceID="EmpDS" DataTextField="EmpName" DataValueField="EmpID" />
<asp:Label runat="server" ID="data" Text='<%# Eval("appBusinessUnit") +";" + Eval("appFunctID") %>' Visible="False"></asp:Label>
</EditItemTemplate>
<ItemTemplate>
<asp:Label runat="server" Text='<%# Eval("EmpName") %>'/>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="JobApprovalsDS" runat="server"
ConnectionString="<%$ ConnectionStrings:JobClose %>"
SelectCommand="up_JobApprovalsSelect"
SelectCommandType="StoredProcedure"
UpdateCommand="up_JobApprovalsUpdate">
<SelectParameters>
<asp:Parameter Name="ShowAll" DefaultValue="1" />
<asp:Parameter Name="AllPhases" DefaultValue="1" />
<asp:ControlParameter Name="BusinessUnit" ControlID="ddlEditJob" />
</SelectParameters>
<UpdateParameters>
<asp:Parameter Name="#BusinessUnit" Type="String"/>
<asp:Parameter Name="#FunctID" Type="Int32"/>
<asp:Parameter Name="#EmpID" Type="Int32"/>
<asp:Parameter Name="#UpdateDate" Type="DateTime"/>
</UpdateParameters>
</asp:SqlDataSource>
C#:
protected void JobGV_OnRowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName.Equals("Update"))
{
int empid = 0;
string[] data;
int index = int.Parse(e.CommandArgument.ToString());
GridViewRow row = JobGV.Rows[index];
DropDownList ddlemp = (DropDownList) row.FindControl("ddlEmps");
empid = int.Parse(ddlemp.SelectedValue);
Label lbl = (Label) row.FindControl("data");
data = lbl.Text.Split(';');
JobApprovalsDS.UpdateParameters["#BusinessUnit"].DefaultValue = data[0];
JobApprovalsDS.UpdateParameters["#FunctID"].DefaultValue = data[1];
JobApprovalsDS.UpdateParameters["#EmpID"].DefaultValue = empid.ToString();
//JobApprovalsDS.UpdateParameters.Add("BusinessUnit", data[0]);
//JobApprovalsDS.UpdateParameters.Add("FunctID", data[1]);
//JobApprovalsDS.UpdateParameters.Add("EmpID", empid.ToString());
}
}
protected void JobGV_OnRowUpdating(object sender, GridViewUpdateEventArgs e)
{
JobApprovalsDS.Update();
}
Are you talking about the update process??
Well, in your SqlDataSource, you're not specifying that the UpdateCommand is talking to a stored procedure... you need to specify the UpdateCommandType, too! (not just the SelectCommandType)
<asp:SqlDataSource ID="JobApprovalsDS" runat="server"
ConnectionString="<%$ ConnectionStrings:JobClose %>"
SelectCommand="up_JobApprovalsSelect"
SelectCommandType="StoredProcedure"
UpdateCommand="up_JobApprovalsUpdate"
UpdateCommandType="StoredProcedure" > **** this is missing from your code!

changing DetailsViewMode on Page_Load event

I have a simple DetailsView control connected to a data source consisting of two T-SQL queries (which work fine). However, when I try to change the mode (depending on the id in the URL) to "Edit" on Page_Load event nothing shows while "Insert" works fine. Everything seems properly data-bound.
Also, how do I access the BoundField value (the text itself) from code-behind (FindControl always returns null for some reason)? I want to have a default value there when the page loads.
Markup:
<body>
<form id="form1" runat="server">
<div class="register" runat="server">
<asp:DetailsView ID="DV" runat="server" HorizontalAlign="Center"
Height="100px" Width="170px"
AutoGenerateRows="False" DataSourceID="RegisterUser"
OnItemCommand="Button_click"
OnItemInserted="Insert_click" OnItemUpdated="Edit_click">
<Fields>
<asp:BoundField DataField="username" HeaderText="Name"
SortExpression="username" />
<asp:TemplateField HeaderText="Password">
<EditItemTemplate>
<asp:TextBox ID="Password" runat="server" TextMode="Password" Text='<%# Bind("userPassword") %>'></asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="userEmail" HeaderText="Email"
SortExpression="userEmail" />
<asp:CommandField ShowInsertButton="True" ShowEditButton="True" />
</Fields>
</asp:DetailsView>
<asp:SqlDataSource ID="RegisterUser" runat="server"
ConnectionString="<%$ ConnectionStrings:usersConnectionString %>"
InsertCommand="INSERT INTO korisnik(username, userPassword, userEmail) VALUES (#username, #userPassword, #userEmail)"
UpdateCommand="UPDATE korisnik SET userPassword = #userPassword, userEmail = #userEmail WHERE (username = #username)">
<InsertParameters>
<asp:Parameter Name="username" Type="String" />
<asp:Parameter Name="userPassword" Type="String" />
<asp:Parameter Name="userEmail" Type="String" />
</InsertParameters>
<UpdateParameters>
<asp:Parameter Name="userPassword" Type="String" />
<asp:Parameter Name="userEmail" Type="String" />
<asp:Parameter Name="username" Type="String" />
</UpdateParameters>
</asp:SqlDataSource>
<asp:Label ID="Message_label" ForeColor="red" Visible="false" runat="server" Text="[messageLabel]"></asp:Label>
</div>
</form>
</body>
Code-behind:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
string id = Request.QueryString["id"];
// EDIT mode
if (id == "Change_data_button")
{
DV.DefaultMode = DetailsViewMode.Edit;
//DV.DataSource = RegisterUser;
//DV.DataBind();
DV.Fields[0].Visible = false; // preventing the value from being changed (one cannot change a username)
/* found this snippet somewhere but FindControl returns null */
TextBox user;
user = (TextBox)DV.FindControl("username");
user.Text = Session["LoggedUser"].ToString();
}
// INSERT mode
else if (id == "Register_button")
{
DV.DefaultMode = DetailsViewMode.Insert;
}
}
}
First, I don't see any setting for SelectCommand in SqlDataSource control named RegisterUser, I don't think that you will have data in DetailsView to edit in EditMode.
So you have to set SelectCommand (also SelectParameters if have them) such as the following sample
<asp:SqlDataSource ID="RegisterUser" runat="server"
ConnectionString="<%$ ConnectionStrings:usersConnectionString %>"
SelectCommand="SELECT * FROM korisnik WHERE username = #username"
InsertCommand="INSERT INTO korisnik(username, userPassword, userEmail) VALUES (#username, #userPassword, #userEmail)"
UpdateCommand="UPDATE korisnik SET userPassword = #userPassword, userEmail = #userEmail WHERE (username = #username)">
<SelectParameters>
<asp:Parameter Name="username" Type="String" />
</SelectParameters>
<InsertParameters>
<asp:Parameter Name="username" Type="String" />
<asp:Parameter Name="userPassword" Type="String" />
<asp:Parameter Name="userEmail" Type="String" />
</InsertParameters>
<UpdateParameters>
<asp:Parameter Name="userPassword" Type="String" />
<asp:Parameter Name="userEmail" Type="String" />
<asp:Parameter Name="username" Type="String" />
</UpdateParameters>
</asp:SqlDataSource>
Secound, in Page_Load handler, this line user = (TextBox)DV.FindControl("username"); should always be null, because you don't have a control names "username", you have only DataField named "username".
If you want to hide username field in edit mode, you have to set username field as Key of DetailView (DataKeyNames setting). But I suggest that you could set username to be read-only instead of hiding it (set ReadOnly="true" in BoundField). Final, try to get their values in ItemUpdating event handler (OnItemUpdating setting)
Here is the sample as my suggestion:
<asp:DetailsView ID="DV" runat="server" HorizontalAlign="Center"
Height="100px" Width="170px"
AutoGenerateRows="False" DataSourceID="RegisterUser"
OnItemCommand="Button_click"
OnItemInserted="Insert_click" OnItemUpdated="Edit_click"
OnItemUpdating="DV_ItemUpdating"
DataKeyNames="username">
<Fields>
<asp:BoundField DataField="username" HeaderText="Name"
SortExpression="username"
ReadOnly="true"/>
<asp:TemplateField HeaderText="Password">
<EditItemTemplate>
<asp:TextBox ID="Password" runat="server" TextMode="Password" Text='<%# Bind("userPassword") %>'></asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="userEmail" HeaderText="Email"
SortExpression="userEmail" />
<asp:CommandField ShowInsertButton="True" ShowEditButton="True" />
</Fields>
</asp:DetailsView>
Code-behide:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
string id = Request.QueryString["id"];
// EDIT mode
if (id == "Change_data_button")
{
DV.DefaultMode = DetailsViewMode.Edit;
}
// INSERT mode
else if (id == "Register_button")
{
DV.DefaultMode = DetailsViewMode.Insert;
}
}
}
protected void DV_ItemUpdating(object sender, DetailsViewUpdateEventArgs e)
{
string username = e.Keys["username"].ToString();
TextBox txtPassword = (TextBox)DV.FindControl("Password");
string password = txtPassword.Text;
string email = e.NewValues["userEmail"].ToString();
RegisterUser.UpdateParameters["userPassword"].DefaultValue = password;
RegisterUser.UpdateParameters["userEmail"].DefaultValue = email;
RegisterUser.UpdateParameters["username"].DefaultValue = username;
RegisterUser.Update();
}
You should use: DetailsView.ChangeMode() method to programmatically switch the DetailsView control between edit, insert, and read-only mode.
if (id == "Change_data_button")
{
DV.ChangeMode(DetailsViewMode.Edit);
//DV.DataSource = RegisterUser;
//DV.DataBind();
...
...
}
Also, access the Bound Fields value as::
string _userName = DV.Rows[0].Cells[0].Text.ToString();

Casting object to CheckBox in bulk updates

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?

Categories

Resources