ASP.NET ListView SQLDataSource - asp.net

I use Visual Studio 2015 with a WebForm Webapplication.
I have add a ListView and a SQLDataSource.
The SQLDataSource is connected to a SQL-Server.
Using the ListView operations like Edit, Insert and Delete are working.
I have a textbox where the user can enter a City-Name and press a button that will update the SQLDataSource with a SQL-Query
With this I can search/filter for City-Names.
This works.
But if I click the "Edit" button after a search the search result in the Listview gets removed and all records are displayed
So I can not use "edit" after I have done a search.
How can I run a search and edit one of the found records in the ListView?
.apsx
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="frmMain.aspx.cs" Inherits="DB_mit_GridView.frmMain" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Label ID="Label1" runat="server" Text="Stadt"></asp:Label>
<asp:TextBox ID="txtCity" runat="server"></asp:TextBox>
<asp:Button ID="btnSearch" runat="server" OnClick="btnSearch_Click" Text="Suche" />
</div>
<asp:GridView ID="GridViewDatenAnzeigen" runat="server" AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False" DataKeyNames="CustomerID" DataSourceID="SqlDataSource1" PageSize="5">
<Columns>
<asp:CommandField ShowSelectButton="True" />
<asp:BoundField DataField="CustomerID" HeaderText="CustomerID" ReadOnly="True" SortExpression="CustomerID" />
<asp:BoundField DataField="CustomerName" HeaderText="CustomerName" SortExpression="CustomerName" />
<asp:BoundField DataField="City" HeaderText="City" SortExpression="City" />
<asp:BoundField DataField="PostalCode" HeaderText="PostalCode" SortExpression="PostalCode" />
<asp:BoundField DataField="Country" HeaderText="Country" SortExpression="Country" />
</Columns>
</asp:GridView>
<br />
<asp:ListView ID="ListView1" runat="server" DataKeyNames="CustomerID" DataSourceID="SqlDataSource1" OnSelectedIndexChanged="ListView1_SelectedIndexChanged" InsertItemPosition="LastItem">
<AlternatingItemTemplate>
<tr style="">
<td>
<asp:Button ID="DeleteButton" runat="server" CommandName="Delete" Text="Delete" />
<asp:Button ID="EditButton" runat="server" CommandName="Edit" Text="Edit" />
</td>
<td>
<asp:Label ID="CustomerIDLabel" runat="server" Text='<%# Eval("CustomerID") %>' />
</td>
<td>
<asp:Label ID="CustomerNameLabel" runat="server" Text='<%# Eval("CustomerName") %>' />
</td>
<td>
<asp:Label ID="CityLabel" runat="server" Text='<%# Eval("City") %>' />
</td>
<td>
<asp:Label ID="PostalCodeLabel" runat="server" Text='<%# Eval("PostalCode") %>' />
</td>
<td>
<asp:Label ID="CountryLabel" runat="server" Text='<%# Eval("Country") %>' />
</td>
</tr>
</AlternatingItemTemplate>
<EditItemTemplate>
<tr style="">
<td>
<asp:Button ID="UpdateButton" runat="server" CommandName="Update" Text="Update" />
<asp:Button ID="CancelButton" runat="server" CommandName="Cancel" Text="Cancel" />
</td>
<td>
<asp:Label ID="CustomerIDLabel1" runat="server" Text='<%# Eval("CustomerID") %>' />
</td>
<td>
<asp:TextBox ID="CustomerNameTextBox" runat="server" Text='<%# Bind("CustomerName") %>' />
</td>
<td>
<asp:TextBox ID="CityTextBox" runat="server" Text='<%# Bind("City") %>' />
</td>
<td>
<asp:TextBox ID="PostalCodeTextBox" runat="server" Text='<%# Bind("PostalCode") %>' />
</td>
<td>
<asp:TextBox ID="CountryTextBox" runat="server" Text='<%# Bind("Country") %>' />
</td>
</tr>
</EditItemTemplate>
<EmptyDataTemplate>
<table runat="server" style="">
<tr>
<td>No data was returned.</td>
</tr>
</table>
</EmptyDataTemplate>
<InsertItemTemplate>
<tr style="">
<td>
<asp:Button ID="InsertButton" runat="server" CommandName="Insert" Text="Insert" />
<asp:Button ID="CancelButton" runat="server" CommandName="Cancel" Text="Clear" />
</td>
<td>
<asp:TextBox ID="CustomerIDTextBox" runat="server" Text='<%# Bind("CustomerID") %>' />
</td>
<td>
<asp:TextBox ID="CustomerNameTextBox" runat="server" Text='<%# Bind("CustomerName") %>' />
</td>
<td>
<asp:TextBox ID="CityTextBox" runat="server" Text='<%# Bind("City") %>' />
</td>
<td>
<asp:TextBox ID="PostalCodeTextBox" runat="server" Text='<%# Bind("PostalCode") %>' />
</td>
<td>
<asp:TextBox ID="CountryTextBox" runat="server" Text='<%# Bind("Country") %>' />
</td>
</tr>
</InsertItemTemplate>
<ItemTemplate>
<tr style="">
<td>
<asp:Button ID="DeleteButton" runat="server" CommandName="Delete" Text="Delete" />
<asp:Button ID="EditButton" runat="server" CommandName="Edit" Text="Edit" />
</td>
<td>
<asp:Label ID="CustomerIDLabel" runat="server" Text='<%# Eval("CustomerID") %>' />
</td>
<td>
<asp:Label ID="CustomerNameLabel" runat="server" Text='<%# Eval("CustomerName") %>' />
</td>
<td>
<asp:Label ID="CityLabel" runat="server" Text='<%# Eval("City") %>' />
</td>
<td>
<asp:Label ID="PostalCodeLabel" runat="server" Text='<%# Eval("PostalCode") %>' />
</td>
<td>
<asp:Label ID="CountryLabel" runat="server" Text='<%# Eval("Country") %>' />
</td>
</tr>
</ItemTemplate>
<LayoutTemplate>
<table runat="server">
<tr runat="server">
<td runat="server">
<table id="itemPlaceholderContainer" runat="server" border="0" style="">
<tr runat="server" style="">
<th runat="server"></th>
<th runat="server">CustomerID</th>
<th runat="server">CustomerName</th>
<th runat="server">City</th>
<th runat="server">PostalCode</th>
<th runat="server">Country</th>
</tr>
<tr id="itemPlaceholder" runat="server">
</tr>
</table>
</td>
</tr>
<tr runat="server">
<td runat="server" style="">
<asp:DataPager ID="DataPager1" runat="server" >
<Fields>
<asp:NextPreviousPagerField ButtonType="Button" ShowFirstPageButton="True" ShowNextPageButton="False" ShowPreviousPageButton="False" />
<asp:NumericPagerField />
<asp:NextPreviousPagerField ButtonType="Button" ShowLastPageButton="True" ShowNextPageButton="False" ShowPreviousPageButton="False" />
</Fields>
</asp:DataPager>
</td>
</tr>
</table>
</LayoutTemplate>
<SelectedItemTemplate>
<tr style="">
<td>
<asp:Button ID="DeleteButton" runat="server" CommandName="Delete" Text="Delete" />
<asp:Button ID="EditButton" runat="server" CommandName="Edit" Text="Edit" />
</td>
<td>
<asp:Label ID="CustomerIDLabel" runat="server" Text='<%# Eval("CustomerID") %>' />
</td>
<td>
<asp:Label ID="CustomerNameLabel" runat="server" Text='<%# Eval("CustomerName") %>' />
</td>
<td>
<asp:Label ID="CityLabel" runat="server" Text='<%# Eval("City") %>' />
</td>
<td>
<asp:Label ID="PostalCodeLabel" runat="server" Text='<%# Eval("PostalCode") %>' />
</td>
<td>
<asp:Label ID="CountryLabel" runat="server" Text='<%# Eval("Country") %>' />
</td>
</tr>
</SelectedItemTemplate>
</asp:ListView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:TestDBConnectionString %>" SelectCommand="SELECT * FROM [Customers]" DeleteCommand="DELETE FROM [Customers] WHERE [CustomerID] = #original_CustomerID" InsertCommand="INSERT INTO [Customers] ([CustomerID], [CustomerName], [City], [PostalCode], [Country]) VALUES (#CustomerID, #CustomerName, #City, #PostalCode, #Country)" OldValuesParameterFormatString="original_{0}" UpdateCommand="UPDATE [Customers] SET [CustomerName] = #CustomerName, [City] = #City, [PostalCode] = #PostalCode, [Country] = #Country WHERE [CustomerID] = #original_CustomerID">
<DeleteParameters>
<asp:Parameter Name="original_CustomerID" Type="String" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="CustomerID" Type="String" />
<asp:Parameter Name="CustomerName" Type="String" />
<asp:Parameter Name="City" Type="String" />
<asp:Parameter Name="PostalCode" Type="String" />
<asp:Parameter Name="Country" Type="String" />
</InsertParameters>
<UpdateParameters>
<asp:Parameter Name="CustomerName" Type="String" />
<asp:Parameter Name="City" Type="String" />
<asp:Parameter Name="PostalCode" Type="String" />
<asp:Parameter Name="Country" Type="String" />
<asp:Parameter Name="original_CustomerID" Type="String" />
</UpdateParameters>
</asp:SqlDataSource>
<br />
</form>
</body>
</html>
.aspx.cs
public partial class frmMain : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnSearch_Click(object sender, EventArgs e)
{
//Search is done here
SqlDataSource1.SelectCommand = "SELECT* FROM[Customers] where City = '" + txtCity.Text +"'";
}
protected void ListView1_SelectedIndexChanged(object sender, EventArgs e)
{
}
}

just chage the datasource select command and add select parameter
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:TestDBConnectionString %>" SelectCommand="SELECT * FROM [Customers] WHERE City LiKE #City + '%'" DeleteCommand="DELETE FROM [Customers] WHERE [CustomerID] = #original_CustomerID" InsertCommand="INSERT INTO [Customers] ([CustomerID], [CustomerName], [City], [PostalCode], [Country]) VALUES (#CustomerID, #CustomerName, #City, #PostalCode, #Country)" OldValuesParameterFormatString="original_{0}" UpdateCommand="UPDATE [Customers] SET [CustomerName] = #CustomerName, [City] = #City, [PostalCode] = #PostalCode, [Country] = #Country WHERE [CustomerID] = #original_CustomerID">
<DeleteParameters>
<asp:Parameter Name="original_CustomerID" Type="String" />
</DeleteParameters>
<SelectParameters>
<asp:ControlParameter ControlID="txtCity" Name="City" PropertyName="Text" Type="String" DefaultValue="%" />
</SelectParameters>
<InsertParameters>
<asp:Parameter Name="CustomerID" Type="String" />
<asp:Parameter Name="CustomerName" Type="String" />
<asp:Parameter Name="City" Type="String" />
<asp:Parameter Name="PostalCode" Type="String" />
<asp:Parameter Name="Country" Type="String" />
</InsertParameters>
<UpdateParameters>
<asp:Parameter Name="CustomerName" Type="String" />
<asp:Parameter Name="City" Type="String" />
<asp:Parameter Name="PostalCode" Type="String" />
<asp:Parameter Name="Country" Type="String" />
<asp:Parameter Name="original_CustomerID" Type="String" />
</UpdateParameters>
</asp:SqlDataSource>
and after that remove the code behinde select query
protected void btnSearch_Click(object sender, EventArgs e)
{
//Search is done here
// SqlDataSource1.SelectCommand = "SELECT* FROM[Customers] where City = '" + txtCity.Text +"'";
}

Related

ASP: Listview buttons do nothing

I have a listview control databound to a database in my ASP project and I have it set so that it can be edited. The listview is inside a multiview and it loads the information perfectly but clicking on the edit button doesn't do anything. The listview is in an update panel which I though might be part of it but putting the listview outside the update panel just causes the multivew to change view back the default page load view.
I have a perfectly functional editable listview in a previous project in almost identical circumstances and I just can't figure out what's made this one not work. I've tried deleting and remaking but this problem seems to be affecting any listview I make in the multiview. On other listviews where I've implemented the 'insert' feature, the insert button does not do anything either.
My code is below:
<asp:UpdatePanel ID="UpdatePanel3" runat="server">
<ContentTemplate>
<asp:ListView ID="ListView2" runat="server" DataKeyNames="StudentID"
DataSourceID="SqlDataSource10" GroupItemCount="3">
<AlternatingItemTemplate>
<td runat="server" style="background-color: #FFFFFF;color: #284775;">
StudentID:
<asp:Label ID="StudentIDLabel" runat="server" Text='<%# Eval("StudentID") %>' />
<br />
CurrentSchoolID:
<asp:Label ID="CurrentSchoolIDLabel" runat="server"
Text='<%# Eval("CurrentSchoolID") %>' />
<br />
Gender:
<asp:Label ID="GenderLabel" runat="server" Text='<%# Eval("Gender") %>' />
<br />
Fname:
<asp:Label ID="FnameLabel" runat="server" Text='<%# Eval("Fname") %>' />
<br />
Lname:
<asp:Label ID="LnameLabel" runat="server" Text='<%# Eval("Lname") %>' />
<br />
ParentCarer:
<asp:Label ID="ParentCarerLabel" runat="server"
Text='<%# Eval("ParentCarer") %>' />
<br />
StAddress:
<asp:Label ID="StAddressLabel" runat="server" Text='<%# Eval("StAddress") %>' />
<br />
suburb:
<asp:Label ID="suburbLabel" runat="server" Text='<%# Eval("suburb") %>' />
<br />
postCode:
<asp:Label ID="postCodeLabel" runat="server" Text='<%# Eval("postCode") %>' />
<br />
DOB:
<asp:Label ID="DOBLabel" runat="server" Text='<%# Eval("DOB") %>' />
<br />
homePhone:
<asp:Label ID="homePhoneLabel" runat="server" Text='<%# Eval("homePhone") %>' />
<br />
MobilePhone:
<asp:Label ID="MobilePhoneLabel" runat="server"
Text='<%# Eval("MobilePhone") %>' />
<br />
WorkPhone:
<asp:Label ID="WorkPhoneLabel" runat="server" Text='<%# Eval("WorkPhone") %>' />
<br />
email:
<asp:Label ID="emailLabel" runat="server" Text='<%# Eval("email") %>' />
<br />
UserID:
<asp:Label ID="UserIDLabel" runat="server" Text='<%# Eval("UserID") %>' />
<br />
Username:
<asp:Label ID="UsernameLabel" runat="server" Text='<%# Eval("Username") %>' />
<br />
<asp:Button ID="EditButton" runat="server" CommandName="Edit" Text="Edit" />
<br />
</td>
</AlternatingItemTemplate>
<EditItemTemplate>
<td runat="server" style="background-color: #999999;">
StudentID:
<asp:Label ID="StudentIDLabel1" runat="server"
Text='<%# Eval("StudentID") %>' />
<br />
CurrentSchoolID:
<asp:TextBox ID="CurrentSchoolIDTextBox" runat="server"
Text='<%# Bind("CurrentSchoolID") %>' />
<br />
Gender:
<asp:TextBox ID="GenderTextBox" runat="server" Text='<%# Bind("Gender") %>' />
<br />
Fname:
<asp:TextBox ID="FnameTextBox" runat="server" Text='<%# Bind("Fname") %>' />
<br />
Lname:
<asp:TextBox ID="LnameTextBox" runat="server" Text='<%# Bind("Lname") %>' />
<br />
ParentCarer:
<asp:TextBox ID="ParentCarerTextBox" runat="server"
Text='<%# Bind("ParentCarer") %>' />
<br />
StAddress:
<asp:TextBox ID="StAddressTextBox" runat="server"
Text='<%# Bind("StAddress") %>' />
<br />
suburb:
<asp:TextBox ID="suburbTextBox" runat="server" Text='<%# Bind("suburb") %>' />
<br />
postCode:
<asp:TextBox ID="postCodeTextBox" runat="server"
Text='<%# Bind("postCode") %>' />
<br />
DOB:
<asp:TextBox ID="DOBTextBox" runat="server" Text='<%# Bind("DOB") %>' />
<br />
homePhone:
<asp:TextBox ID="homePhoneTextBox" runat="server"
Text='<%# Bind("homePhone") %>' />
<br />
MobilePhone:
<asp:TextBox ID="MobilePhoneTextBox" runat="server"
Text='<%# Bind("MobilePhone") %>' />
<br />
WorkPhone:
<asp:TextBox ID="WorkPhoneTextBox" runat="server"
Text='<%# Bind("WorkPhone") %>' />
<br />
email:
<asp:TextBox ID="emailTextBox" runat="server" Text='<%# Bind("email") %>' />
<br />
UserID:
<asp:TextBox ID="UserIDTextBox" runat="server" Text='<%# Bind("UserID") %>' />
<br />
Username:
<asp:TextBox ID="UsernameTextBox" runat="server"
Text='<%# Bind("Username") %>' />
<br />
<asp:Button ID="UpdateButton" runat="server" CommandName="Update"
Text="Update" />
<br />
<asp:Button ID="CancelButton" runat="server" CommandName="Cancel"
Text="Cancel" />
<br />
</td>
</EditItemTemplate>
<EmptyDataTemplate>
<table runat="server"
style="background-color: #FFFFFF;border-collapse: collapse;border-color: #999999;border-style:none;border-width:1px;">
<tr>
<td>
No data was returned.</td>
</tr>
</table>
</EmptyDataTemplate>
<EmptyItemTemplate>
<td runat="server" />
</EmptyItemTemplate>
<GroupTemplate>
<tr ID="itemPlaceholderContainer" runat="server">
<td ID="itemPlaceholder" runat="server">
</td>
</tr>
</GroupTemplate>
<InsertItemTemplate>
<td runat="server" style="">
CurrentSchoolID:
<asp:TextBox ID="CurrentSchoolIDTextBox" runat="server"
Text='<%# Bind("CurrentSchoolID") %>' />
<br />
Gender:
<asp:TextBox ID="GenderTextBox" runat="server" Text='<%# Bind("Gender") %>' />
<br />
Fname:
<asp:TextBox ID="FnameTextBox" runat="server" Text='<%# Bind("Fname") %>' />
<br />
Lname:
<asp:TextBox ID="LnameTextBox" runat="server" Text='<%# Bind("Lname") %>' />
<br />
ParentCarer:
<asp:TextBox ID="ParentCarerTextBox" runat="server"
Text='<%# Bind("ParentCarer") %>' />
<br />
StAddress:
<asp:TextBox ID="StAddressTextBox" runat="server"
Text='<%# Bind("StAddress") %>' />
<br />
suburb:
<asp:TextBox ID="suburbTextBox" runat="server" Text='<%# Bind("suburb") %>' />
<br />
postCode:
<asp:TextBox ID="postCodeTextBox" runat="server"
Text='<%# Bind("postCode") %>' />
<br />
DOB:
<asp:TextBox ID="DOBTextBox" runat="server" Text='<%# Bind("DOB") %>' />
<br />
homePhone:
<asp:TextBox ID="homePhoneTextBox" runat="server"
Text='<%# Bind("homePhone") %>' />
<br />
MobilePhone:
<asp:TextBox ID="MobilePhoneTextBox" runat="server"
Text='<%# Bind("MobilePhone") %>' />
<br />
WorkPhone:
<asp:TextBox ID="WorkPhoneTextBox" runat="server"
Text='<%# Bind("WorkPhone") %>' />
<br />
email:
<asp:TextBox ID="emailTextBox" runat="server" Text='<%# Bind("email") %>' />
<br />
UserID:
<asp:TextBox ID="UserIDTextBox" runat="server" Text='<%# Bind("UserID") %>' />
<br />
Username:
<asp:TextBox ID="UsernameTextBox" runat="server"
Text='<%# Bind("Username") %>' />
<br />
<asp:Button ID="InsertButton" runat="server" CommandName="Insert"
Text="Insert" />
<br />
<asp:Button ID="CancelButton" runat="server" CommandName="Cancel"
Text="Clear" />
<br />
</td>
</InsertItemTemplate>
<ItemTemplate>
<td runat="server" style="background-color: #E0FFFF;color: #333333;">
StudentID:
<asp:Label ID="StudentIDLabel" runat="server" Text='<%# Eval("StudentID") %>' />
<br />
CurrentSchoolID:
<asp:Label ID="CurrentSchoolIDLabel" runat="server"
Text='<%# Eval("CurrentSchoolID") %>' />
<br />
Gender:
<asp:Label ID="GenderLabel" runat="server" Text='<%# Eval("Gender") %>' />
<br />
Fname:
<asp:Label ID="FnameLabel" runat="server" Text='<%# Eval("Fname") %>' />
<br />
Lname:
<asp:Label ID="LnameLabel" runat="server" Text='<%# Eval("Lname") %>' />
<br />
ParentCarer:
<asp:Label ID="ParentCarerLabel" runat="server"
Text='<%# Eval("ParentCarer") %>' />
<br />
StAddress:
<asp:Label ID="StAddressLabel" runat="server" Text='<%# Eval("StAddress") %>' />
<br />
suburb:
<asp:Label ID="suburbLabel" runat="server" Text='<%# Eval("suburb") %>' />
<br />
postCode:
<asp:Label ID="postCodeLabel" runat="server" Text='<%# Eval("postCode") %>' />
<br />
DOB:
<asp:Label ID="DOBLabel" runat="server" Text='<%# Eval("DOB") %>' />
<br />
homePhone:
<asp:Label ID="homePhoneLabel" runat="server" Text='<%# Eval("homePhone") %>' />
<br />
MobilePhone:
<asp:Label ID="MobilePhoneLabel" runat="server"
Text='<%# Eval("MobilePhone") %>' />
<br />
WorkPhone:
<asp:Label ID="WorkPhoneLabel" runat="server" Text='<%# Eval("WorkPhone") %>' />
<br />
email:
<asp:Label ID="emailLabel" runat="server" Text='<%# Eval("email") %>' />
<br />
UserID:
<asp:Label ID="UserIDLabel" runat="server" Text='<%# Eval("UserID") %>' />
<br />
Username:
<asp:Label ID="UsernameLabel" runat="server" Text='<%# Eval("Username") %>' />
<br />
<asp:Button ID="EditButton" runat="server" CommandName="Edit" Text="Edit" />
<br />
</td>
</ItemTemplate>
<LayoutTemplate>
<table runat="server">
<tr runat="server">
<td runat="server">
<table ID="groupPlaceholderContainer" runat="server" border="1"
style="background-color: #FFFFFF;border-collapse: collapse;border-color: #999999;border-style:none;border-width:1px;font-family: Verdana, Arial, Helvetica, sans-serif;">
<tr ID="groupPlaceholder" runat="server">
</tr>
</table>
</td>
</tr>
<tr runat="server">
<td runat="server"
style="text-align: center;background-color: #5D7B9D;font-family: Verdana, Arial, Helvetica, sans-serif;color: #FFFFFF">
</td>
</tr>
</table>
</LayoutTemplate>
<SelectedItemTemplate>
<td runat="server"
style="background-color: #E2DED6;font-weight: bold;color: #333333;">
StudentID:
<asp:Label ID="StudentIDLabel" runat="server" Text='<%# Eval("StudentID") %>' />
<br />
CurrentSchoolID:
<asp:Label ID="CurrentSchoolIDLabel" runat="server"
Text='<%# Eval("CurrentSchoolID") %>' />
<br />
Gender:
<asp:Label ID="GenderLabel" runat="server" Text='<%# Eval("Gender") %>' />
<br />
Fname:
<asp:Label ID="FnameLabel" runat="server" Text='<%# Eval("Fname") %>' />
<br />
Lname:
<asp:Label ID="LnameLabel" runat="server" Text='<%# Eval("Lname") %>' />
<br />
ParentCarer:
<asp:Label ID="ParentCarerLabel" runat="server"
Text='<%# Eval("ParentCarer") %>' />
<br />
StAddress:
<asp:Label ID="StAddressLabel" runat="server" Text='<%# Eval("StAddress") %>' />
<br />
suburb:
<asp:Label ID="suburbLabel" runat="server" Text='<%# Eval("suburb") %>' />
<br />
postCode:
<asp:Label ID="postCodeLabel" runat="server" Text='<%# Eval("postCode") %>' />
<br />
DOB:
<asp:Label ID="DOBLabel" runat="server" Text='<%# Eval("DOB") %>' />
<br />
homePhone:
<asp:Label ID="homePhoneLabel" runat="server" Text='<%# Eval("homePhone") %>' />
<br />
MobilePhone:
<asp:Label ID="MobilePhoneLabel" runat="server"
Text='<%# Eval("MobilePhone") %>' />
<br />
WorkPhone:
<asp:Label ID="WorkPhoneLabel" runat="server" Text='<%# Eval("WorkPhone") %>' />
<br />
email:
<asp:Label ID="emailLabel" runat="server" Text='<%# Eval("email") %>' />
<br />
UserID:
<asp:Label ID="UserIDLabel" runat="server" Text='<%# Eval("UserID") %>' />
<br />
Username:
<asp:Label ID="UsernameLabel" runat="server" Text='<%# Eval("Username") %>' />
<br />
<asp:Button ID="EditButton" runat="server" CommandName="Edit" Text="Edit" />
<br />
</td>
</SelectedItemTemplate>
</asp:ListView>
<asp:SqlDataSource ID="SqlDataSource10" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
DeleteCommand="DELETE FROM [Student] WHERE [StudentID] = #StudentID"
InsertCommand="INSERT INTO [Student] ([CurrentSchoolID], [Gender], [Fname], [Lname], [ParentCarer], [StAddress], [suburb], [postCode], [DOB], [homePhone], [MobilePhone], [WorkPhone], [email], [UserID], [Username]) VALUES (#CurrentSchoolID, #Gender, #Fname, #Lname, #ParentCarer, #StAddress, #suburb, #postCode, #DOB, #homePhone, #MobilePhone, #WorkPhone, #email, #UserID, #Username)"
SelectCommand="SELECT * FROM [Student] WHERE ([Username] = #Username)"
UpdateCommand="UPDATE [Student] SET [CurrentSchoolID] = #CurrentSchoolID, [Gender] = #Gender, [Fname] = #Fname, [Lname] = #Lname, [ParentCarer] = #ParentCarer, [StAddress] = #StAddress, [suburb] = #suburb, [postCode] = #postCode, [DOB] = #DOB, [homePhone] = #homePhone, [MobilePhone] = #MobilePhone, [WorkPhone] = #WorkPhone, [email] = #email, [UserID] = #UserID, [Username] = #Username WHERE [StudentID] = #StudentID">
<DeleteParameters>
<asp:Parameter Name="StudentID" Type="Int32" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="CurrentSchoolID" Type="Int32" />
<asp:Parameter Name="Gender" Type="String" />
<asp:Parameter Name="Fname" Type="String" />
<asp:Parameter Name="Lname" Type="String" />
<asp:Parameter Name="ParentCarer" Type="String" />
<asp:Parameter Name="StAddress" Type="String" />
<asp:Parameter Name="suburb" Type="String" />
<asp:Parameter Name="postCode" Type="Int32" />
<asp:Parameter DbType="Date" Name="DOB" />
<asp:Parameter Name="homePhone" Type="String" />
<asp:Parameter Name="MobilePhone" Type="String" />
<asp:Parameter Name="WorkPhone" Type="String" />
<asp:Parameter Name="email" Type="String" />
<asp:Parameter Name="UserID" Type="Int32" />
<asp:Parameter Name="Username" Type="String" />
</InsertParameters>
<SelectParameters>
<asp:SessionParameter Name="Username" SessionField="Username" Type="String" />
</SelectParameters>
<UpdateParameters>
<asp:Parameter Name="CurrentSchoolID" Type="Int32" />
<asp:Parameter Name="Gender" Type="String" />
<asp:Parameter Name="Fname" Type="String" />
<asp:Parameter Name="Lname" Type="String" />
<asp:Parameter Name="ParentCarer" Type="String" />
<asp:Parameter Name="StAddress" Type="String" />
<asp:Parameter Name="suburb" Type="String" />
<asp:Parameter Name="postCode" Type="Int32" />
<asp:Parameter DbType="Date" Name="DOB" />
<asp:Parameter Name="homePhone" Type="String" />
<asp:Parameter Name="MobilePhone" Type="String" />
<asp:Parameter Name="WorkPhone" Type="String" />
<asp:Parameter Name="email" Type="String" />
<asp:Parameter Name="UserID" Type="Int32" />
<asp:Parameter Name="Username" Type="String" />
<asp:Parameter Name="StudentID" Type="Int32" />
</UpdateParameters>
</asp:SqlDataSource>
</ContentTemplate>
</asp:UpdatePanel>
C# Code:
protected void Page_Load(object sender, EventArgs e)
{
MultiView1.ActiveViewIndex = 0;
if (!Page.IsPostBack)
{
if (User.IsInRole("Student"))
{
MultiView1.ActiveViewIndex = 2;
}
else if (User.IsInRole("Staff"))
{
MultiView1.ActiveViewIndex = 6;
}
else if (User.IsInRole("Admin"))
{
MultiView1.ActiveViewIndex = 7;
}
}
}
changed my code on page load to:
if(!User.Identity.IsAuthenticated){
MultiView1.ActiveViewIndex = 0;
}
Now works fine

Count Records inside the Gridview and show a label message

I have a "Pending Records Page" I want to count all the records that in pending. For example I want to add in my homepage "You have (# of records) new Pending Records" I want to add that in my page. Just like in Facebook. Literally it's just like a notification message :) e.g I want to appear that "You have 23 new Pending Records" in my homepage. What is the code for that? Please help.
Here's the screenshot of my homepage. I edited in paint. You can see the label text message that I want to appear.
Here'e my code for my Pending Records Page:
<%# Page Language="C#" Debug="true" %>
<%# Import Namespace="System" %>
<%# Import Namespace="System.Data" %>
<%# Import Namespace = "System.Data.SqlClient" %>
<%# Import Namespace= "System.Data.OleDb" %>
<title>Pending Records</title>
<head>
<style type="text/css">
.style1 {
background-image: url('images/pending.jpg');
}
.style2 {
margin-bottom: 0px;
}
</style>
<script type="text/javascript">
<!--
function FP_swapImgRestore() {//v1.0
var doc=document,i; if(doc.$imgSwaps) { for(i=0;i<doc.$imgSwaps.length;i++) {
var elm=doc.$imgSwaps[i]; if(elm) { elm.src=elm.$src; elm.$src=null; } }
doc.$imgSwaps=null; }
}
function FP_swapImg() {//v1.0
var doc=document,args=arguments,elm,n; doc.$imgSwaps=new Array(); for(n=2; n<args.length;
n+=2) { elm=FP_getObjectByID(args[n]); if(elm) { doc.$imgSwaps[doc.$imgSwaps.length]=elm;
elm.$src=elm.src; elm.src=args[n+1]; } }
}
function FP_preloadImgs() {//v1.0
var d=document,a=arguments; if(!d.FP_imgs) d.FP_imgs=new Array();
for(var i=0; i<a.length; i++) { d.FP_imgs[i]=new Image; d.FP_imgs[i].src=a[i]; }
}
function FP_getObjectByID(id,o) {//v1.0
var c,el,els,f,m,n; if(!o)o=document; if(o.getElementById) el=o.getElementById(id);
else if(o.layers) c=o.layers; else if(o.all) el=o.all[id]; if(el) return el;
if(o.id==id || o.name==id) return o; if(o.childNodes) c=o.childNodes; if(c)
for(n=0; n<c.length; n++) { el=FP_getObjectByID(id,c[n]); if(el) return el; }
f=o.forms; if(f) for(n=0; n<f.length; n++) { els=f[n].elements;
for(m=0; m<els.length; m++){ el=FP_getObjectByID(id,els[n]); if(el) return el; } }
return null;
}
// -->
</script>
</head>
<script runat="server" type="css">
protected void PendingRecordsGridview_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
PendingRecordsGridview.PageIndex = e.NewPageIndex;
PendingRecordsGridview.DataBind();
}
protected void Page_Load(object sender, EventArgs e)
{
}
protected void PendingRecordsGridview_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "accept")
{
Session["ID"] = e.CommandArgument.ToString();
OleDbConnection con = new OleDbConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
con.Open();
OleDbCommand cmd1 = new OleDbCommand("INSERT INTO DriversRecords (ID, FirstName, LastName, MiddleName, Address, Gender, ContactNumber, PlateNumber, Color, Brand, LiscensedNumber, [Image]) SELECT ID, FirstName, LastName, MiddleName, Address, Gender, ContactNumber, PlateNumber, Color, Brand, LiscensedNumber, [Image] FROM PendingRecords where ID="+Session["ID"].ToString()+"", con);
OleDbCommand cmd2 = new OleDbCommand("delete from PendingRecords where ID="+Session["ID"].ToString()+"", con);
cmd1.ExecuteNonQuery();
cmd2.ExecuteNonQuery();
PendingRecordsGridview.DataBind();
}
}
public void PendingRecordsGridview_RowDeleting(Object sender, GridViewDeleteEventArgs e)
{
}
</script>
<body onload="FP_preloadImgs(/*url*/'images/backhover.jpg')" style="margin: 0; background-color: #808080">
<form id="form1" runat="server" class="style2" style="height: 646px">
<table style="width: 1150px; height: 646px" cellspacing="0" cellpadding="0" align="center" class="style1">
<!-- MSTableType="layout" -->
<tr>
<td> </td>
<td></td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td style="height: 98px"> </td>
</tr>
<tr>
<td> </td>
<td></td>
<td valign="top"><a href="passwordprotect.asp">
<img alt="" src="images/back.jpg" width="83" height="32" id="img1" onmouseout="FP_swapImgRestore()" onmouseover="FP_swapImg(1,1,/*id*/'img1',/*url*/'images/backhover.jpg')"></a></td>
<td> </td>
<td> </td>
<td> </td>
<td style="height: 36px"> </td>
</tr>
<tr>
<td> </td>
<td></td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td style="height: 23px"> </td>
</tr>
<tr>
<td> </td>
<td></td>
<td> </td>
<td> </td>
<td valign="top">
<asp:SqlDataSource runat="server" id="sd1" ProviderName="<%$ ConnectionStrings:ConnectionString.ProviderName %>" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" SelectCommand="SELECT * FROM [PendingRecords]" DeleteCommand="DELETE FROM [PendingRecords] WHERE [ID] = ?" InsertCommand="INSERT INTO [PendingRecords] ([Username], [Password], [FirstName], [LastName], [MiddleName], [Address], [Gender], [ContactNumber], [PlateNumber], [Color], [Brand], [LiscensedNumber]) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)" UpdateCommand="UPDATE [PendingRecords] SET [Username] = ?, [Password] = ?, [FirstName] = ?, [LastName] = ?, [MiddleName] = ?, [Address] = ?, [Gender] = ?, [ContactNumber] = ?, [PlateNumber] = ?, [Color] = ?, [Brand] = ?, [LiscensedNumber] = ? WHERE [ID] = ?">
<DeleteParameters>
<asp:parameter Name="ID" Type="Int32" />
</DeleteParameters>
<UpdateParameters>
<asp:parameter Name="Username" Type="String" />
<asp:parameter Name="Password" Type="String" />
<asp:parameter Name="FirstName" Type="String" />
<asp:parameter Name="LastName" Type="String" />
<asp:parameter Name="MiddleName" Type="String" />
<asp:parameter Name="Address" Type="String" />
<asp:parameter Name="Gender" Type="String" />
<asp:parameter Name="ContactNumber" Type="String" />
<asp:parameter Name="PlateNumber" Type="String" />
<asp:parameter Name="Color" Type="String" />
<asp:parameter Name="Brand" Type="String" />
<asp:parameter Name="LiscensedNumber" Type="String" />
<asp:parameter Name="ID" Type="Int32" />
</UpdateParameters>
<InsertParameters>
<asp:parameter Name="Username" Type="String" />
<asp:parameter Name="Password" Type="String" />
<asp:parameter Name="FirstName" Type="String" />
<asp:parameter Name="LastName" Type="String" />
<asp:parameter Name="MiddleName" Type="String" />
<asp:parameter Name="Address" Type="String" />
<asp:parameter Name="Gender" Type="String" />
<asp:parameter Name="ContactNumber" Type="String" />
<asp:parameter Name="PlateNumber" Type="String" />
<asp:parameter Name="Color" Type="String" />
<asp:parameter Name="Brand" Type="String" />
<asp:parameter Name="LiscensedNumber" Type="String" />
</InsertParameters>
</asp:SqlDataSource>
</td>
<td> </td>
<td style="height: 33px;"> </td>
</tr>
<tr>
<td> </td>
<td></td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td style="height: 30px"> </td>
</tr>
<tr>
<td> </td>
<td valign="top" colspan="5">
<asp:GridView OnPageIndexChanging="PendingRecordsGridview_PageIndexChanging" ID="PendingRecordsGridview" runat="server" AutoGenerateColumns="False" DataKeyNames="ID" OnRowcommand="PendingRecordsGridview_RowCommand" DataSourceID="sd1" BorderStyle="Ridge" BackColor="White" BorderColor="Black" BorderWidth="3px" CellPadding="4" Width="1089px" PageSize="2" AllowPaging="True" OnRowDeleting="PendingRecordsGridview_RowDeleting">
<RowStyle ForeColor="#003399" HorizontalAlign="Center" />
<Columns>
<asp:templatefield HeaderText="Accept">
<ItemTemplate>
<asp:Button CommandArgument='<%# Bind("ID") %>' ID="Button1" runat="server" CausesValidation="false" CommandName="accept" Text="Accept" />
</ItemTemplate>
</asp:templatefield>
<asp:templatefield HeaderText="Ignore">
<ItemTemplate>
<asp:Button ID="deleteButton" runat="server" CommandName="Delete" Text="Ignore" CausesValidation="False" OnClientClick="return confirm('Are you sure you want to cancel this request?');" />
</ItemTemplate>
</asp:templatefield>
<asp:templatefield HeaderText="First Name" SortExpression="FirstName">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("FirstName") %>'>
</asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label3" runat="server" Text='<%# Bind("FirstName") %>'>
</asp:Label>
</ItemTemplate>
</asp:templatefield>
<asp:templatefield HeaderText="Last Name" SortExpression="LastName">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("LastName") %>'>
</asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label4" runat="server" Text='<%# Bind("LastName") %>'>
</asp:Label>
</ItemTemplate>
</asp:templatefield>
<asp:templatefield HeaderText="Middle Name" SortExpression="MiddleLastName">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("MiddleName") %>'>
</asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label5" runat="server" Text='<%# Bind("MiddleName") %>'>
</asp:Label>
</ItemTemplate>
</asp:templatefield>
<asp:templatefield HeaderText="Address" SortExpression="Address">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("Address") %>'>
</asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label6" runat="server" Text='<%# Bind("Address") %>'>
</asp:Label>
</ItemTemplate>
</asp:templatefield>
<asp:templatefield HeaderText="Gender" SortExpression="Gender">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("Gender") %>'>
</asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label7" runat="server" Text='<%# Bind("Gender") %>'>
</asp:Label>
</ItemTemplate>
</asp:templatefield>
<asp:templatefield HeaderText="Contact No." SortExpression="ContactNumber">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("ContactNumber") %>'>
</asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label18" runat="server" Text='<%# Bind("ContactNumber") %>'>
</asp:Label>
</ItemTemplate>
</asp:templatefield>
<asp:templatefield HeaderText="Plate No." SortExpression="PlateNumber">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("PlateNumber") %>'>
</asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label19" runat="server" Text='<%# Bind("PlateNumber") %>'>
</asp:Label>
</ItemTemplate>
</asp:templatefield>
<asp:templatefield HeaderText="Mobile Color" SortExpression="Color">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("Color") %>'>
</asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label11" runat="server" Text='<%# Bind("Color") %>'>
</asp:Label>
</ItemTemplate>
</asp:templatefield>
<asp:templatefield HeaderText="Brand" SortExpression="Brand">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("Brand") %>'>
</asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label12" runat="server" Text='<%# Bind("Brand") %>'>
</asp:Label>
</ItemTemplate>
</asp:templatefield>
<asp:templatefield HeaderText="Liscenced No." SortExpression="LiscensedNumber">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("LiscensedNumber") %>'>
</asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label10" runat="server" Text='<%# Bind("LiscensedNumber") %>'>
</asp:Label>
</ItemTemplate>
</asp:templatefield>
<asp:templatefield>
<HeaderTemplate>
Image
</HeaderTemplate>
<ItemTemplate>
<img src="data:image/jpg;base64,<%# Eval("Image") != System.DBNull.Value ? Convert.ToBase64String((byte[])Eval("Image")) : string.Empty %>" alt="image" height="85" width="85" />
</ItemTemplate>
</asp:templatefield>
</Columns>
<FooterStyle BackColor="#99CCCC" ForeColor="#003399" />
<PagerStyle HorizontalAlign="Center" BackColor="#999999" ForeColor="#003399" />
<SelectedRowStyle BackColor="#009999" Font-Bold="True" ForeColor="#CCFF99" />
<HeaderStyle BackColor="#A0A0A0" Font-Bold="True" ForeColor="#003399" HorizontalAlign="Center" />
<AlternatingRowStyle BorderColor="Black" BorderWidth="3px" BorderStyle="Ridge" />
</asp:GridView>
</td>
<td style="height: 333px"> </td>
</tr>
<tr>
<td style="width: 29px"> </td>
<td style="width: 3px"></td>
<td style="width: 95px"> </td>
<td style="width: 33px"> </td>
<td style="width: 542px"> </td>
<td style="width: 422px"> </td>
<td style="height: 93px; width: 26px"> </td>
</tr>
</table>
</form>
This is just pseudo code, but it is really close to what you'll put in your code.
select count(id) as PendingRecordCount from pendingrecords where id=Session["ID"].ToString()

Set a label text message to count the records

I'm asking again with full clear explanations.
I want to add a label text message on my admin.aspx like this (please see the image below...I just edit it in paint so that you can see the output)
In my case. I want to count the records that in-pending. Then there will be a label text message that notify how many records are in-pending. What is the code for that label text message?
Here's my code for my Pending Records Page (Pending.aspx).
<%# Page Language="C#" Debug="true" %>
<%# Import Namespace="System" %>
<%# Import Namespace="System.Data" %>
<%# Import Namespace = "System.Data.SqlClient" %>
<%# Import Namespace= "System.Data.OleDb" %>
<title>Pending Records</title>
<head>
<style type="text/css">
.style1 {
background-image: url('images/pending.jpg');
}
.style2 {
margin-bottom: 0px;
}
</style>
<script type="text/javascript">
<!--
function FP_swapImgRestore() {//v1.0
var doc=document,i; if(doc.$imgSwaps) { for(i=0;i<doc.$imgSwaps.length;i++) {
var elm=doc.$imgSwaps[i]; if(elm) { elm.src=elm.$src; elm.$src=null; } }
doc.$imgSwaps=null; }
}
function FP_swapImg() {//v1.0
var doc=document,args=arguments,elm,n; doc.$imgSwaps=new Array(); for(n=2; n<args.length;
n+=2) { elm=FP_getObjectByID(args[n]); if(elm) { doc.$imgSwaps[doc.$imgSwaps.length]=elm;
elm.$src=elm.src; elm.src=args[n+1]; } }
}
function FP_preloadImgs() {//v1.0
var d=document,a=arguments; if(!d.FP_imgs) d.FP_imgs=new Array();
for(var i=0; i<a.length; i++) { d.FP_imgs[i]=new Image; d.FP_imgs[i].src=a[i]; }
}
function FP_getObjectByID(id,o) {//v1.0
var c,el,els,f,m,n; if(!o)o=document; if(o.getElementById) el=o.getElementById(id);
else if(o.layers) c=o.layers; else if(o.all) el=o.all[id]; if(el) return el;
if(o.id==id || o.name==id) return o; if(o.childNodes) c=o.childNodes; if(c)
for(n=0; n<c.length; n++) { el=FP_getObjectByID(id,c[n]); if(el) return el; }
f=o.forms; if(f) for(n=0; n<f.length; n++) { els=f[n].elements;
for(m=0; m<els.length; m++){ el=FP_getObjectByID(id,els[n]); if(el) return el; } }
return null;
}
// -->
</script>
</head>
<script runat="server" type="css">
protected void PendingRecordsGridview_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
PendingRecordsGridview.PageIndex = e.NewPageIndex;
PendingRecordsGridview.DataBind();
}
protected void Page_Load(object sender, EventArgs e)
{
}
protected void PendingRecordsGridview_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "accept")
{
Session["ID"] = e.CommandArgument.ToString();
OleDbConnection con = new OleDbConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
con.Open();
OleDbCommand cmd1 = new OleDbCommand("INSERT INTO DriversRecords (ID, FirstName, LastName, MiddleName, Address, Gender, ContactNumber, PlateNumber, Color, Brand, LiscensedNumber, [Image]) SELECT ID, FirstName, LastName, MiddleName, Address, Gender, ContactNumber, PlateNumber, Color, Brand, LiscensedNumber, [Image] FROM PendingRecords where ID="+Session["ID"].ToString()+"", con);
OleDbCommand cmd2 = new OleDbCommand("delete from PendingRecords where ID="+Session["ID"].ToString()+"", con);
cmd1.ExecuteNonQuery();
cmd2.ExecuteNonQuery();
PendingRecordsGridview.DataBind();
}
}
public void PendingRecordsGridview_RowDeleting(Object sender, GridViewDeleteEventArgs e)
{
}
</script>
<body onload="FP_preloadImgs(/*url*/'images/backhover.jpg')" style="margin: 0; background-color: #808080">
<form id="form1" runat="server" class="style2" style="height: 646px">
<table style="width: 1150px; height: 646px" cellspacing="0" cellpadding="0" align="center" class="style1">
<!-- MSTableType="layout" -->
<tr>
<td> </td>
<td></td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td style="height: 98px"> </td>
</tr>
<tr>
<td> </td>
<td></td>
<td valign="top"><a href="passwordprotect.asp">
<img alt="" src="images/back.jpg" width="83" height="32" id="img1" onmouseout="FP_swapImgRestore()" onmouseover="FP_swapImg(1,1,/*id*/'img1',/*url*/'images/backhover.jpg')"></a></td>
<td> </td>
<td> </td>
<td> </td>
<td style="height: 36px"> </td>
</tr>
<tr>
<td> </td>
<td></td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td style="height: 23px"> </td>
</tr>
<tr>
<td> </td>
<td></td>
<td> </td>
<td> </td>
<td valign="top">
<asp:SqlDataSource runat="server" id="sd1" ProviderName="<%$ ConnectionStrings:ConnectionString.ProviderName %>" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" SelectCommand="SELECT * FROM [PendingRecords]" DeleteCommand="DELETE FROM [PendingRecords] WHERE [ID] = ?" InsertCommand="INSERT INTO [PendingRecords] ([Username], [Password], [FirstName], [LastName], [MiddleName], [Address], [Gender], [ContactNumber], [PlateNumber], [Color], [Brand], [LiscensedNumber]) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)" UpdateCommand="UPDATE [PendingRecords] SET [Username] = ?, [Password] = ?, [FirstName] = ?, [LastName] = ?, [MiddleName] = ?, [Address] = ?, [Gender] = ?, [ContactNumber] = ?, [PlateNumber] = ?, [Color] = ?, [Brand] = ?, [LiscensedNumber] = ? WHERE [ID] = ?">
<DeleteParameters>
<asp:parameter Name="ID" Type="Int32" />
</DeleteParameters>
<UpdateParameters>
<asp:parameter Name="Username" Type="String" />
<asp:parameter Name="Password" Type="String" />
<asp:parameter Name="FirstName" Type="String" />
<asp:parameter Name="LastName" Type="String" />
<asp:parameter Name="MiddleName" Type="String" />
<asp:parameter Name="Address" Type="String" />
<asp:parameter Name="Gender" Type="String" />
<asp:parameter Name="ContactNumber" Type="String" />
<asp:parameter Name="PlateNumber" Type="String" />
<asp:parameter Name="Color" Type="String" />
<asp:parameter Name="Brand" Type="String" />
<asp:parameter Name="LiscensedNumber" Type="String" />
<asp:parameter Name="ID" Type="Int32" />
</UpdateParameters>
<InsertParameters>
<asp:parameter Name="Username" Type="String" />
<asp:parameter Name="Password" Type="String" />
<asp:parameter Name="FirstName" Type="String" />
<asp:parameter Name="LastName" Type="String" />
<asp:parameter Name="MiddleName" Type="String" />
<asp:parameter Name="Address" Type="String" />
<asp:parameter Name="Gender" Type="String" />
<asp:parameter Name="ContactNumber" Type="String" />
<asp:parameter Name="PlateNumber" Type="String" />
<asp:parameter Name="Color" Type="String" />
<asp:parameter Name="Brand" Type="String" />
<asp:parameter Name="LiscensedNumber" Type="String" />
</InsertParameters>
</asp:SqlDataSource>
</td>
<td> </td>
<td style="height: 33px;"> </td>
</tr>
<tr>
<td> </td>
<td></td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td style="height: 30px"> </td>
</tr>
<tr>
<td> </td>
<td valign="top" colspan="5">
<asp:GridView OnPageIndexChanging="PendingRecordsGridview_PageIndexChanging" ID="PendingRecordsGridview" runat="server" AutoGenerateColumns="False" DataKeyNames="ID" OnRowcommand="PendingRecordsGridview_RowCommand" DataSourceID="sd1" BorderStyle="Ridge" BackColor="White" BorderColor="Black" BorderWidth="3px" CellPadding="4" Width="1089px" PageSize="2" AllowPaging="True" OnRowDeleting="PendingRecordsGridview_RowDeleting">
<RowStyle ForeColor="#003399" HorizontalAlign="Center" />
<Columns>
<asp:templatefield HeaderText="Accept">
<ItemTemplate>
<asp:Button CommandArgument='<%# Bind("ID") %>' ID="Button1" runat="server" CausesValidation="false" CommandName="accept" Text="Accept" />
</ItemTemplate>
</asp:templatefield>
<asp:templatefield HeaderText="Ignore">
<ItemTemplate>
<asp:Button ID="deleteButton" runat="server" CommandName="Delete" Text="Ignore" CausesValidation="False" OnClientClick="return confirm('Are you sure you want to cancel this request?');" />
</ItemTemplate>
</asp:templatefield>
<asp:templatefield HeaderText="First Name" SortExpression="FirstName">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("FirstName") %>'>
</asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label3" runat="server" Text='<%# Bind("FirstName") %>'>
</asp:Label>
</ItemTemplate>
</asp:templatefield>
<asp:templatefield HeaderText="Last Name" SortExpression="LastName">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("LastName") %>'>
</asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label4" runat="server" Text='<%# Bind("LastName") %>'>
</asp:Label>
</ItemTemplate>
</asp:templatefield>
<asp:templatefield HeaderText="Middle Name" SortExpression="MiddleLastName">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("MiddleName") %>'>
</asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label5" runat="server" Text='<%# Bind("MiddleName") %>'>
</asp:Label>
</ItemTemplate>
</asp:templatefield>
<asp:templatefield HeaderText="Address" SortExpression="Address">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("Address") %>'>
</asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label6" runat="server" Text='<%# Bind("Address") %>'>
</asp:Label>
</ItemTemplate>
</asp:templatefield>
<asp:templatefield HeaderText="Gender" SortExpression="Gender">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("Gender") %>'>
</asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label7" runat="server" Text='<%# Bind("Gender") %>'>
</asp:Label>
</ItemTemplate>
</asp:templatefield>
<asp:templatefield HeaderText="Contact No." SortExpression="ContactNumber">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("ContactNumber") %>'>
</asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label18" runat="server" Text='<%# Bind("ContactNumber") %>'>
</asp:Label>
</ItemTemplate>
</asp:templatefield>
<asp:templatefield HeaderText="Plate No." SortExpression="PlateNumber">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("PlateNumber") %>'>
</asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label19" runat="server" Text='<%# Bind("PlateNumber") %>'>
</asp:Label>
</ItemTemplate>
</asp:templatefield>
<asp:templatefield HeaderText="Mobile Color" SortExpression="Color">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("Color") %>'>
</asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label11" runat="server" Text='<%# Bind("Color") %>'>
</asp:Label>
</ItemTemplate>
</asp:templatefield>
<asp:templatefield HeaderText="Brand" SortExpression="Brand">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("Brand") %>'>
</asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label12" runat="server" Text='<%# Bind("Brand") %>'>
</asp:Label>
</ItemTemplate>
</asp:templatefield>
<asp:templatefield HeaderText="Liscenced No." SortExpression="LiscensedNumber">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("LiscensedNumber") %>'>
</asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label10" runat="server" Text='<%# Bind("LiscensedNumber") %>'>
</asp:Label>
</ItemTemplate>
</asp:templatefield>
<asp:templatefield>
<HeaderTemplate>
Image
</HeaderTemplate>
<ItemTemplate>
<img src="data:image/jpg;base64,<%# Eval("Image") != System.DBNull.Value ? Convert.ToBase64String((byte[])Eval("Image")) : string.Empty %>" alt="image" height="85" width="85" />
</ItemTemplate>
</asp:templatefield>
</Columns>
<FooterStyle BackColor="#99CCCC" ForeColor="#003399" />
<PagerStyle HorizontalAlign="Center" BackColor="#999999" ForeColor="#003399" />
<SelectedRowStyle BackColor="#009999" Font-Bold="True" ForeColor="#CCFF99" />
<HeaderStyle BackColor="#A0A0A0" Font-Bold="True" ForeColor="#003399" HorizontalAlign="Center" />
<AlternatingRowStyle BorderColor="Black" BorderWidth="3px" BorderStyle="Ridge" />
</asp:GridView>
</td>
<td style="height: 333px"> </td>
</tr>
<tr>
<td style="width: 29px"> </td>
<td style="width: 3px"></td>
<td style="width: 95px"> </td>
<td style="width: 33px"> </td>
<td style="width: 542px"> </td>
<td style="width: 422px"> </td>
<td style="height: 93px; width: 26px"> </td>
</tr>
</table>
</form>
You can execute the PendingRecords query while loading Admin.aspx:
Example: Assuming you have a DataAccessLayer class for handling database operations
protected void Page_Load(object sender, EventArgs e){
if(!IsPostBack){
int pendingRecords;
// You can place this query in a stored procedure
string query = "SELECT count(*) FROM [PendingRecords]";
// Execute query or its stored procedure
// Show total pending records in label
lblPending.Text = pendingRecords.ToString();
}
}
You can load your pending request count from the back end coding using your aspx.cs page for a particular aspx page and in page load method you can add your code to get the particular count you can store it in a variable and bingo that variable value can be used to get what you exactly want.

Empty Dictionary Error on Delete with SqlDataSource - ASP.net ListView

I'm trying to make a simple ListView with optimistic concurrency. It uses the VS-automatically-generated Delete, Insert, Update statements (except 1 change to insert: see code).
Insert and Edit work fine and commit to the database. When trying to delete, I get this error:
You have specified that your delete command compares all values on SqlDataSource 'MySourceHere', but the dictionary passed in for values is empty. Pass in a valid dictionary for delete or change your mode to OverwriteChanges.
I've tried just changing "CompareAllValues" to "OverwriteChanges" to postpone concurrency work for later, but that "breaks" Update and Delete commands, which just seem to refresh the ListView with the old values. The only threads I could find that resolved this issue involved changing to "OverwriteChanges" or were people who didn't have a "DataKeyNames" declared. Relevent markup is below (I hope).
Any thoughts?
<asp:SqlDataSource ID="ManageUsersSource" runat="server"
ConflictDetection="CompareAllValues"
ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
DeleteCommand="DELETE FROM [DUSER] WHERE [userid] = ? AND (([username] = ?) OR ([username] IS NULL AND ? IS NULL)) AND (([userpass] = ?) OR ([userpass] IS NULL AND ? IS NULL))"
InsertCommand="INSERT INTO [DUSER] ([username], [userpass]) VALUES (?, ?)"
OldValuesParameterFormatString="original_{0}"
ProviderName="<%$ ConnectionStrings:ConnectionString.ProviderName %>"
SelectCommand="SELECT * FROM [DUSER] ORDER BY [userid] ASC"
UpdateCommand="UPDATE [DUSER] SET [username] = ?, [userpass] = ? WHERE [userid] = ? AND (([username] = ?) OR ([username] IS NULL AND ? IS NULL)) AND (([userpass] = ?) OR ([userpass] IS NULL AND ? IS NULL))">
<DeleteParameters>
<asp:Parameter Name="original_userid" Type="Int16" />
<asp:Parameter Name="original_username" Type="String" />
<asp:Parameter Name="original_username" Type="String" />
<asp:Parameter Name="original_userpass" Type="String" />
<asp:Parameter Name="original_userpass" Type="String" />
</DeleteParameters>
<InsertParameters>
<%--This is removed since [userid] is an automatically generated index.--%>
<%--<asp:Parameter Name="userid" Type="Int16" />--%>
<asp:Parameter Name="username" Type="String" />
<asp:Parameter Name="userpass" Type="String" />
</InsertParameters>
<UpdateParameters>
<asp:Parameter Name="username" Type="String" />
<asp:Parameter Name="userpass" Type="String" />
<asp:Parameter Name="original_userid" Type="Int16" />
<asp:Parameter Name="original_username" Type="String" />
<asp:Parameter Name="original_username" Type="String" />
<asp:Parameter Name="original_userpass" Type="String" />
<asp:Parameter Name="original_userpass" Type="String" />
</UpdateParameters>
</asp:SqlDataSource>
<asp:ListView ID="ListView1" runat="server" DataKeyNames="userid"
DataSourceID="ManageUsersSource" InsertItemPosition="LastItem">
<AlternatingItemTemplate>
<tr style="background-color:#FFF8DC;">
<td>
<asp:Button ID="DeleteButton" runat="server" CommandName="Delete"
Text="Delete" />
<asp:Button ID="EditButton" runat="server" CommandName="Edit" Text="Edit" />
</td>
<td>
<asp:Label ID="useridLabel" runat="server" Text='<%# Eval("userid") %>' />
</td>
<td>
<asp:Label ID="usernameLabel" runat="server" Text='<%# Eval("username") %>' />
</td>
<td>
<asp:Label ID="userpassLabel" runat="server" Text='<%# Eval("userpass") %>' />
</td>
</tr>
</AlternatingItemTemplate>
<EditItemTemplate>
<tr style="background-color:#008A8C;color: #FFFFFF;">
<td>
<asp:Button ID="UpdateButton" runat="server" CommandName="Update"
Text="Update" />
<asp:Button ID="CancelButton" runat="server" CommandName="Cancel"
Text="Cancel" />
</td>
<td>
<asp:Label ID="useridLabel1" runat="server" Text='<%# Eval("userid") %>' />
</td>
<td>
<asp:TextBox ID="usernameTextBox" runat="server"
Text='<%# Bind("username") %>' />
</td>
<td>
<asp:TextBox ID="userpassTextBox" runat="server"
Text='<%# Bind("userpass") %>' />
</td>
</tr>
</EditItemTemplate>
<EmptyDataTemplate>
<table runat="server"
style="background-color: #FFFFFF;border-collapse: collapse;border-color: #999999;border-style:none;border-width:1px;">
<tr>
<td>
No data was returned.</td>
</tr>
</table>
</EmptyDataTemplate>
<InsertItemTemplate>
<tr style="">
<td>
<asp:Button ID="InsertButton" runat="server" CommandName="Insert"
Text="Insert" />
<asp:Button ID="CancelButton" runat="server" CommandName="Cancel"
Text="Clear" />
</td>
<td>
</td>
<td>
<asp:TextBox ID="usernameTextBox" runat="server"
Text='<%# Bind("username") %>' />
</td>
<td>
<asp:TextBox ID="userpassTextBox" runat="server"
Text='<%# Bind("userpass") %>' />
</td>
</tr>
</InsertItemTemplate>
<ItemTemplate>
<tr style="background-color:#DCDCDC;color: #000000;">
<td>
<asp:Button ID="DeleteButton" runat="server" CommandName="Delete"
Text="Delete" />
<asp:Button ID="EditButton" runat="server" CommandName="Edit" Text="Edit" />
</td>
<td>
<asp:Label ID="useridLabel" runat="server" Text='<%# Eval("userid") %>' />
</td>
<td>
<asp:Label ID="usernameLabel" runat="server" Text='<%# Eval("username") %>' />
</td>
<td>
<asp:Label ID="userpassLabel" runat="server" Text='<%# Eval("userpass") %>' />
</td>
</tr>
</ItemTemplate>
<LayoutTemplate>
<table runat="server">
<tr runat="server">
<td runat="server">
<table ID="itemPlaceholderContainer" runat="server" border="1"
style="background-color: #FFFFFF;border-collapse: collapse;border-color: #999999;border-style:none;border-width:1px;font-family: Verdana, Arial, Helvetica, sans-serif;">
<tr runat="server" style="background-color:#DCDCDC;color: #000000;">
<th runat="server">
</th>
<th runat="server">
userid</th>
<th runat="server">
username</th>
<th runat="server">
userpass</th>
</tr>
<tr ID="itemPlaceholder" runat="server">
</tr>
</table>
</td>
</tr>
<tr runat="server">
<td runat="server"
style="text-align: center;background-color: #CCCCCC;font-family: Verdana, Arial, Helvetica, sans-serif;color: #000000;">
<asp:DataPager ID="DataPager1" runat="server">
<Fields>
<asp:NextPreviousPagerField ButtonType="Button" ShowFirstPageButton="True"
ShowLastPageButton="True" />
</Fields>
</asp:DataPager>
</td>
</tr>
</table>
</LayoutTemplate>
<SelectedItemTemplate>
<tr style="background-color:#008A8C;font-weight: bold;color: #FFFFFF;">
<td>
<asp:Button ID="DeleteButton" runat="server" CommandName="Delete"
Text="Delete" />
<asp:Button ID="EditButton" runat="server" CommandName="Edit" Text="Edit" />
</td>
<td>
<asp:Label ID="useridLabel" runat="server" Text='<%# Eval("userid") %>' />
</td>
<td>
<asp:Label ID="usernameLabel" runat="server" Text='<%# Eval("username") %>' />
</td>
<td>
<asp:Label ID="userpassLabel" runat="server" Text='<%# Eval("userpass") %>' />
</td>
</tr>
</SelectedItemTemplate>
</asp:ListView>
Changing the non-Primary Key fields to use "Bind" instead of "Eval" in my ItemTemplate/AlternatingItemTemplate (just like an Edit Template) was apparently needed to properly pass along the old values.
This was a case of using automatically generated markup without fully understanding it (I still don't, really.)
You could try simplifying your Update and Delete Commands.
Since userid (your DataKeyName) is automatically generated and, therefore, unique, you do not need the extra parameters.
So, your UpdateCommand would be
"UPDATE [DUSER] SET [username] = ?, [userpass] = ? WHERE [userid] = ?"
with the following parameters:-
<UpdateParameters>
<asp:Parameter Name="userid" Type="Int16" />
<asp:Parameter Name="username" Type="String" />
<asp:Parameter Name="userpass" Type="String" />
</UpdateParameters>
Your DeleteCommand would be
"DELETE FROM [DUSER] WHERE [userid] = ?"
with the following parameters:-
<DeleteParameters>
<asp:Parameter Name="userid" Type="Int16" />
</DeleteParameters>
Sorry, I forgot to change the ?s and that you want optimistic concurrency.
"UPDATE [DUSER] SET [username] = #username, [userpass] = #userpass WHERE [userid] = #userid And [username] = #original_username And [userpass] = #original_userpass"
"DELETE FROM [DUSER] WHERE [userid] = #userid And [username] = #original_username And [userpass] = #original_userpass"
You will, of course, need to check to see if the row was updated/deleted.
Your InserCommand should also be:-
"INSERT INTO [DUSER] ([username], [userpass]) VALUES (#username, #userpass)"
Assuming username and userpass are set to not allow nulls, which they should be in this case, then the Commands will fail if either parameter is null.
To avoid this, add an <asp:RequiredFieldValidator> to each of the usernameTextBox and userpassTextBox controls to provide client-side validation.
You should also change the IDs of the TextBox controls to match the parameter names.
If you WERE having to deal with null values then you would need the other parts of the generated queries where null comparison is begin used, replacing the ?s with the appropriate parameter.

Ajax control Toolkit Hover Menu with GridView

Hi there I am trying to achieve the same functionality of the Example Hover menu over at http://www.asp.net/ajaxLibrary/AjaxControlToolkitSampleSite/HoverMenu/HoverMenu.aspx
However when my gridview display's and I mouse over the menu comes up but only for the entire gridview not each row like in the example ?. currently the menu buttons do nothing.
<asp:UpdatePanel ID="up1" runat="server">
<ContentTemplate>
<asp:GridView ID="GridView1" runat="server"
AutoGenerateColumns="False" DataSourceID="BookingsSQL"
ShowHeader="False" Width="100%" BackColor="Azure" GridLines="None" >
<Columns>
<asp:BoundField DataField="programme_name" HeaderText="programme_name"
SortExpression="programme_name" />
<asp:BoundField DataField="Start" HeaderText="Start" SortExpression="Start" />
<asp:BoundField DataField="Finish" HeaderText="Finish"
SortExpression="Finish" />
<asp:BoundField DataField="Source" HeaderText="Source"
SortExpression="Source" />
<asp:BoundField DataField="Destination" HeaderText="Destination"
SortExpression="Destination" />
<asp:BoundField DataField="Comment" HeaderText="Comment"
SortExpression="Comment" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="BookingsSQL" runat="server"
ConnectionString="<%$ ConnectionStrings:BookingsConnectionString %>"
SelectCommand="SELECT [programme name] AS programme_name, [Start], [Finish], [Source], [Destination], [Comment] FROM [Bookings]">
</asp:SqlDataSource>
<asp:HoverMenuExtender ID="HoverMenuExtender1" runat="server"
TargetControlID="GridView1"
PopupControlID="PopupMenu"
HoverCssClass="popupHover"
PopupPosition="Left"
OffsetX="0"
OffsetY="0"
PopDelay="50">
</asp:HoverMenuExtender>
<asp:Panel CssClass="popupMenu" ID="PopupMenu" runat="server">
<asp:LinkButton ID="LinkButton1" runat="server" CommandName="Edit" Text="Edit" />
<br />
<asp:LinkButton ID="LinkButton2" runat="server"
CommandName="Delete" Text="Delete" />
</asp:Panel>
</ContentTemplate>
</asp:UpdatePanel>
Tried a few different ways using jquery hover but this would be the best solution.
Any help please . Thanks.
There is solution.
It's not so tricky to implement a HoverExtender for each row since this showed in sample toolkit sample, as to provide columns headers with sorting.
Draw attention that there is surrogate primary key added to Bookings table for allowing editing all fields values. Also there is used jQuery datepicker plugin for editing Start and Finish fields values. You may use DatePickerExtender from the AjaxControlToolkit instead, but in that case those extenders as well as the HoverExtenders must be added for each row in grid separately.
<asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False" DataSourceID="BookingsSQL"
ShowHeader="False" Width="100%" BackColor="Azure" GridLines="None" DataKeyNames="ID">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<table runat="server" visible="<%# Container.DataItemIndex == 0 %>">
<tr>
<th width="20%">
<asp:LinkButton runat="server" CommandName="Sort" CommandArgument="programme_name">
Programme Name
</asp:LinkButton>
</th>
<th width="20%">
<asp:LinkButton runat="server" CommandName="Sort" CommandArgument="Start">
Start
</asp:LinkButton>
</th>
<th width="20%">
<asp:LinkButton runat="server" CommandName="Sort" CommandArgument="Finish">
Finish
</asp:LinkButton>
</th>
<th width="20%">
<asp:LinkButton runat="server" CommandName="Sort" CommandArgument="Source">
Source
</asp:LinkButton>
</th>
<th width="20%">
<asp:LinkButton runat="server" CommandName="Sort" CommandArgument="Destination">
Destination
</asp:LinkButton>
</th>
<th width="20%">
<asp:LinkButton runat="server" CommandName="Sort" CommandArgument="Comment">
Comment
</asp:LinkButton>
</th>
</tr>
</table>
<asp:Panel runat="server" ID="ItemContainer">
<table width="100%">
<tr>
<td width="20%">
<%# Eval("programme_name") %>
</td>
<td width="20%">
<%# Eval("Start", "{0:dd/MM/yyyy}") %>
</td>
<td width="20%">
<%# Eval("Finish", "{0:dd/MM/yyyy}") %>
</td>
<td width="20%">
<%# Eval("Source") %>
</td>
<td width="20%">
<%# Eval("Destination") %>
</td>
<td width="20%">
<%# Eval("Comment") %>
</td>
</tr>
</table>
</asp:Panel>
<asp:Panel CssClass="popupMenu" ID="PopupMenu" runat="server">
<asp:LinkButton ID="LinkButton1" runat="server" CommandName="Edit" Text="Edit" />
<br />
<asp:LinkButton ID="LinkButton2" runat="server" CommandName="Delete" Text="Delete" />
</asp:Panel>
<ajaxToolkit:HoverMenuExtender runat="server" TargetControlID="ItemContainer" PopupControlID="popupMenu"
HoverCssClass="popupHover" PopupPosition="Left" OffsetX="0" OffsetY="0" PopDelay="50">
</ajaxToolkit:HoverMenuExtender>
</ItemTemplate>
<EditItemTemplate>
<table id="Table1" runat="server" visible="<%# Container.DataItemIndex == 0 %>">
<tr>
<th width="20%">
<asp:LinkButton runat="server" CommandName="Sort" CommandArgument="programme_name">
Programme Name
</asp:LinkButton>
</th>
<th width="20%">
<asp:LinkButton runat="server" CommandName="Sort" CommandArgument="Start">
Start
</asp:LinkButton>
</th>
<th width="20%">
<asp:LinkButton runat="server" CommandName="Sort" CommandArgument="Finish">
Finish
</asp:LinkButton>
</th>
<th width="20%">
<asp:LinkButton runat="server" CommandName="Sort" CommandArgument="Source">
Source
</asp:LinkButton>
</th>
<th width="20%">
<asp:LinkButton runat="server" CommandName="Sort" CommandArgument="Destination">
Destination
</asp:LinkButton>
</th>
<th width="20%">
<asp:LinkButton runat="server" CommandName="Sort" CommandArgument="Comment">
Comment
</asp:LinkButton>
</th>
</tr>
</table>
<asp:Panel runat="server" ID="ItemContainer">
<asp:HiddenField runat="server" ID="IdHiddenField" Value='<%# Bind("ID") %>' />
<table width="100%">
<tr>
<td width="20%">
<asp:TextBox ID="TextBox0" runat="server" Text='<%# Bind("programme_name") %>' />
</td>
<td width="20%">
<asp:TextBox ID="TextBox2" CssClass="datePicker" runat="server" Text='<%# Bind("Start", "{0:dd/MM/yyyy}") %>' />
</td>
<td width="20%">
<asp:TextBox ID="TextBox3" CssClass="datePicker" runat="server" Text='<%# Bind("Finish", "{0:dd/MM/yyyy}") %>' />
</td>
<td width="20%">
<asp:TextBox ID="TextBox4" runat="server" Text='<%# Bind("Source") %>' />
</td>
<td width="20%">
<asp:TextBox ID="TextBox5" runat="server" Text='<%# Bind("Destination") %>' />
</td>
<td width="20%">
<asp:TextBox ID="TextBox6" runat="server" Text='<%# Bind("Comment") %>' />
</td>
</tr>
</table>
</asp:Panel>
<asp:Panel CssClass="popupMenu" ID="PopupMenu" runat="server">
<asp:LinkButton ID="LinkButton1" runat="server" CommandName="Update" CausesValidation="true"
Text="Update" />
<br />
<asp:LinkButton ID="LinkButton2" runat="server" CommandName="Cancel" CausesValidation="false"
Text="Cancel" />
</asp:Panel>
<ajaxToolkit:HoverMenuExtender runat="server" TargetControlID="ItemContainer" PopupControlID="popupMenu"
HoverCssClass="popupHover" PopupPosition="Left" OffsetX="0" OffsetY="0" PopDelay="50">
</ajaxToolkit:HoverMenuExtender>
</EditItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="BookingsSQL" runat="server" ConnectionString="<%$ ConnectionStrings:BookingsConnectionString %>"
OldValuesParameterFormatString="original_{0}" ConflictDetection="OverwriteChanges"
SelectCommand="SELECT [ID], [programme name] AS programme_name, [Start], [Finish], [Source], [Destination], [Comment] FROM [Bookings]"
DeleteCommand="DELETE FROM [Bookings] WHERE [programme name] = #ID" InsertCommand="INSERT INTO [Bookings] ([programme name], [Start], [Finish], [Source], [Destination], [Comment]) VALUES (#programme_name, #Start, #Finish, #Source, #Destination, #Comment)"
UpdateCommand="UPDATE [Bookings] SET [programme name] = #programme_name, [Start] = #Start, [Finish] = #Finish, [Source] = #Source, [Destination] = #Destination, [Comment] = #Comment WHERE [ID] = #ID">
<DeleteParameters>
<asp:Parameter Name="ID" Type="Int32" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="programme_name" Type="String" />
<asp:Parameter Name="Start" Type="DateTime" />
<asp:Parameter Name="Finish" Type="DateTime" />
<asp:Parameter Name="Source" Type="String" />
<asp:Parameter Name="Destination" Type="String" />
<asp:Parameter Name="Comment" Type="String" />
</InsertParameters>
<UpdateParameters>
<asp:Parameter Name="ID" Type="Int32" />
<asp:Parameter Name="Start" Type="DateTime" />
<asp:Parameter Name="Finish" Type="DateTime" />
<asp:Parameter Name="Source" Type="String" />
<asp:Parameter Name="Destination" Type="String" />
<asp:Parameter Name="Comment" Type="String" />
<asp:Parameter Name="programme_name" Type="String" />
</UpdateParameters>
</asp:SqlDataSource>
Thanks for such a great help... its working for me i have used SqlDataSource instead of using objectDataSource...
here is my running code that is working great for me....
<asp:UpdatePanel ID="up1" runat="server">
<ContentTemplate>
<asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource1"
ShowHeader="False" Width="100%" BackColor="Azure" GridLines="None" DataKeyNames="PageAddID">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<table id="Table1" runat="server" visible="<%# Container.DataItemIndex == 0 %>">
<tr>
<th width="20%">
<asp:LinkButton ID="LinkButton1" runat="server" CommandName="Sort" CommandArgument="PageName">
Page Name
</asp:LinkButton>
</th>
<th width="20%">
<asp:LinkButton ID="LinkButton2" runat="server" CommandName="Sort" CommandArgument="PageTitle">
PageTitle
</asp:LinkButton>
</th>
<th width="20%">
<asp:LinkButton ID="LinkButton3" runat="server" CommandName="Sort" CommandArgument="Metakeyword">
Metakeyword
</asp:LinkButton>
</th>
<th width="20%">
<asp:LinkButton ID="LinkButton4" runat="server" CommandName="Sort" CommandArgument="Description">
Description
</asp:LinkButton>
</th>
</tr>
</table>
<asp:Panel runat="server" ID="ItemContainer">
<table width="100%">
<tr>
<td width="20%">
<%# Eval("PageName") %>
</td>
<td width="20%">
<%# Eval("PageTitle") %>
</td>
<td width="20%">
<%# Eval("Metakeyword") %>
</td>
<td width="20%">
<%# Eval("Description") %>
</td>
</tr>
</table>
</asp:Panel>
<asp:Panel CssClass="popupMenu" ID="PopupMenu" runat="server">
<asp:LinkButton ID="LinkButton5" runat="server" CommandName="Edit" Text="Edit" />
<br />
<asp:LinkButton ID="LinkButton6" runat="server" CommandName="Delete" Text="Delete" />
</asp:Panel>
<ajaxToolkit:HoverMenuExtender ID="HoverMenuExtender1" runat="server" TargetControlID="ItemContainer" PopupControlID="popupMenu"
HoverCssClass="popupHover" PopupPosition="Left" OffsetX="0" OffsetY="0" PopDelay="10">
</ajaxToolkit:HoverMenuExtender>
</ItemTemplate>
<EditItemTemplate>
<table id="Table1" runat="server" visible="<%# Container.DataItemIndex == 0 %>">
<tr>
<th width="20%">
<asp:LinkButton ID="LinkButton7" runat="server" CommandName="Sort" CommandArgument="PageName">
Page Name
</asp:LinkButton>
</th>
<th width="20%">
<asp:LinkButton ID="LinkButton8" runat="server" CommandName="Sort" CommandArgument="PageTitle">
PageTitle
</asp:LinkButton>
</th>
<th width="20%">
<asp:LinkButton ID="LinkButton9" runat="server" CommandName="Sort" CommandArgument="Metakeyword">
Metakeyword
</asp:LinkButton>
</th>
<th width="20%">
<asp:LinkButton ID="LinkButton10" runat="server" CommandName="Sort" CommandArgument="Description">
Description
</asp:LinkButton>
</th>
</tr>
</table>
<asp:Panel runat="server" ID="ItemContainer">
<asp:HiddenField runat="server" ID="IdHiddenField" Value='<%# Bind("PageAddID") %>' />
<table width="100%">
<tr>
<td width="20%">
<asp:TextBox ID="TextBox0" runat="server" Text='<%# Bind("PageName") %>' />
</td>
<td width="20%">
<asp:TextBox ID="TextBox2" CssClass="datePicker" runat="server" Text='<%# Bind("PageTitle") %>' />
</td>
<td width="20%">
<asp:TextBox ID="TextBox3" CssClass="datePicker" runat="server" Text='<%# Bind("Metakeyword") %>' />
</td>
<td width="20%">
<asp:TextBox ID="TextBox4" runat="server" Text='<%# Bind("Description") %>' />
</td>
</tr>
</table>
</asp:Panel>
<asp:Panel CssClass="popupMenu" ID="PopupMenu" runat="server">
<asp:LinkButton ID="LinkButton1" runat="server" CommandName="Update" CausesValidation="true"
Text="Update" />
<br />
<asp:LinkButton ID="LinkButton2" runat="server" CommandName="Cancel" CausesValidation="false"
Text="Cancel" />
</asp:Panel>
<ajaxToolkit:HoverMenuExtender ID="HoverMenuExtender2" runat="server" TargetControlID="ItemContainer" PopupControlID="popupMenu"
HoverCssClass="popupHover" PopupPosition="Left" OffsetX="0" OffsetY="0" PopDelay="10">
</ajaxToolkit:HoverMenuExtender>
</EditItemTemplate>
</asp:TemplateField>
</Columns>
"
OldValuesParameterFormatString="original_{0}" ConflictDetection="OverwriteChanges"
SelectCommand="SELECT * FROM [AddPages]"
DeleteCommand="DELETE FROM [AddPages] WHERE [PageAddId] = #PageAddID"
UpdateCommand="UPDATE [AddPages] SET [PageName] = #PageName, [PageTitle] = #PageTitle, [Metakeyword] = #Metakeyword, [Description] = #Description WHERE [PageAddID] = #PageAddID">
<DeleteParameters>
<asp:Parameter Name="PageAddID" Type="Int32" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="PageName" Type="string" />
<asp:Parameter Name="PageTitle" Type="string" />
<asp:Parameter Name="Metakeyword" Type="string" />
<asp:Parameter Name="Description" Type="string" />
</InsertParameters>
<UpdateParameters>
<asp:Parameter Name="PageAddID" Type="Int32" />
<asp:Parameter Name="PageName" Type="string" />
<asp:Parameter Name="PageTitle" Type="string" />
<asp:Parameter Name="Metakeyword" Type="string" />
<asp:Parameter Name="Description" Type="string" />
</UpdateParameters>
</ContentTemplate>
</asp:UpdatePanel>

Resources