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.
Related
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 +"'";
}
Help:.....struggling with this null reference. Below is the code any ideas?
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" Runat="Server">
<table class="auto-style1">
<tr>
<td> <asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False" DataKeyNames="PID" DataSourceID="DetailsSqlDataSource" Height="50px" HorizontalAlign="Center" Width="589px" CellPadding="4" ForeColor="#333333" GridLines="None">
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
<CommandRowStyle BackColor="#E2DED6" Font-Bold="True" />
<EditRowStyle BackColor="#999999" />
<FieldHeaderStyle BackColor="#E9ECF1" Font-Bold="True" />
<Fields>
<asp:BoundField DataField="PID" HeaderText="PID" InsertVisible="False" ReadOnly="True" SortExpression="PID" Visible="False" />
<asp:TemplateField HeaderText="Address" SortExpression="PAddress">
<EditItemTemplate>
<asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("PAddress") %>'></asp:TextBox>
</EditItemTemplate>
<InsertItemTemplate>
<asp:TextBox ID="TextBox2" runat="server" Text='<%# Bind("PAddress") %>'></asp:TextBox>
</InsertItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("PAddress") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="City" HeaderText="City" SortExpression="City" />
<asp:BoundField DataField="St" HeaderText="St" SortExpression="St" />
<asp:BoundField DataField="Zip" HeaderText="Zip" SortExpression="Zip" />
<asp:BoundField DataField="Price" HeaderText="Price" SortExpression="Price" />
<asp:BoundField DataField="Beds" HeaderText="Beds" SortExpression="Beds" />
<asp:BoundField DataField="Bath" HeaderText="Bath" SortExpression="Bath" />
<asp:BoundField DataField="SqFt" HeaderText="SqFt" SortExpression="SqFt" />
<asp:BoundField DataField="MLS" HeaderText="MLS" SortExpression="MLS" />
<asp:BoundField DataField="Description" HeaderText="Description" SortExpression="Description" />
<asp:BoundField DataField="AgentName" HeaderText="AgentName" SortExpression="AgentName" />
<asp:BoundField DataField="AgentEmail" HeaderText="AgentEmail" SortExpression="AgentEmail" />
<asp:TemplateField>
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Eval("PhotoPath") %>'></asp:TextBox>
</EditItemTemplate>
<InsertItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Eval("PhotoPath") %>'></asp:TextBox>
</InsertItemTemplate>
<ItemTemplate>
<asp:Image ID="Image1" runat="server" Height="175px" ImageUrl='<%# Eval("PhotoPath") %>' Width="175px" />
</ItemTemplate>
</asp:TemplateField>
</Fields>
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
</asp:DetailsView>
</td>
<td valign="top">
<asp:FormView ID="FormView1" runat="server" DataKeyNames="Id" DataSourceID="RequestInfoSqlDataSource" DefaultMode="Insert">
<EditItemTemplate>
FromAddress:
<asp:TextBox ID="FromAddressTextBox" runat="server" Text='<%# Bind("FromAddress") %>' />
<br />
PropertyAddress:
<asp:TextBox ID="PropertyAddressTextBox" runat="server" Text='<%# Bind("PropertyAddress") %>' />
<br />
Phone:
<asp:TextBox ID="PhoneTextBox" runat="server" Text='<%# Bind("Phone") %>' />
<br />
Message:
<asp:TextBox ID="MessageTextBox" runat="server" Text='<%# Bind("Message") %>' />
<br />
FName:
<asp:TextBox ID="FNameTextBox" runat="server" Text='<%# Bind("FName") %>' />
<br />
LName:
<asp:TextBox ID="LNameTextBox" runat="server" Text='<%# Bind("LName") %>' />
<br />
Id:
<asp:Label ID="IdLabel1" runat="server" Text='<%# Eval("Id") %>' />
<br />
<asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True" CommandName="Update" Text="Update" />
<asp:LinkButton ID="UpdateCancelButton" runat="server" CausesValidation="False" CommandName="Cancel" Text="Cancel" />
</EditItemTemplate>
<InsertItemTemplate>
<table style="width:100%;">
<tr>
<td colspan="2" style="text-align: center; font-weight: 700">Request Information:</td>
</tr>
<tr>
<td>First Name:</td>
<td>
<asp:TextBox ID="FNameTextBox" runat="server" Text='<%# Bind("FName") %>' Width="128px" />
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" controltovalidate="FNameTextBox" runat="server" ErrorMessage="Please enter your first name" style="color: #FF0000; font-weight: 700"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td>Last Name:</td>
<td>
<asp:TextBox ID="LNameTextBox" runat="server" Text='<%# Bind("LName") %>' />
<asp:RequiredFieldValidator ID="RequiredFieldValidator3" controltovalidate="LNameTextBox" runat="server" ErrorMessage="Please enter your last name" style="font-weight: 700; color: #FF0000"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td>Email:</td>
<td>
<asp:TextBox ID="FromAddressTextBox" runat="server" Text='<%# Bind("FromAddress") %>' />
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" ControlToValidate="FromAddressTextBox" runat="server" ErrorMessage="Please enter your email address" style="font-weight: 700; color: #FF0000"></asp:RequiredFieldValidator>
</td>
</tr>
<tr>
<td>Phone:</td>
<td>
<asp:TextBox ID="PhoneTextBox" runat="server" style="text-align: left" Text='<%# Bind("Phone") %>' />
</td>
</tr>
<tr>
<td>Message:</td>
<td>
<asp:TextBox ID="MessageTextBox" runat="server" Height="189px" Text='<%# "Please Send me Information about: "+Detailsview1.DataItem("paddress") + " " +Detailsview1.DataItem("City") %>' TextMode="MultiLine" Width="198px" />
</td>
</tr>
<tr>
<td> </td>
<td>
<asp:LinkButton ID="InsertButton" runat="server" CausesValidation="True" CommandName="Insert" Text="Send Request" />
</td>
</tr>
<tr>
<td> </td>
<td>
<asp:TextBox ID="TextBox3" runat="server" Text='<%# Bind("PropertyAddress") %>'></asp:TextBox>
</td>
</tr>
</table>
<br />
<br />
<br />
</InsertItemTemplate>
<ItemTemplate>
FromAddress:
<asp:Label ID="FromAddressLabel" runat="server" Text='<%# Bind("FromAddress") %>' />
<br />
PropertyAddress:
<asp:Label ID="PropertyAddressLabel" runat="server" Text='<%# Bind("PropertyAddress") %>' />
<br />
Phone:
<asp:Label ID="PhoneLabel" runat="server" Text='<%# Bind("Phone") %>' />
<br />
Message:
<asp:Label ID="MessageLabel" runat="server" Text='<%# Bind("Message") %>' />
<br />
FName:
<asp:Label ID="FNameLabel" runat="server" Text='<%# Bind("FName") %>' />
<br />
LName:
<asp:Label ID="LNameLabel" runat="server" Text='<%# Bind("LName") %>' />
<br />
Id:
<asp:Label ID="IdLabel" runat="server" Text='<%# Eval("Id") %>' />
<br />
<asp:LinkButton ID="EditButton" runat="server" CausesValidation="False" CommandName="Edit" Text="Edit" />
<asp:LinkButton ID="DeleteButton" runat="server" CausesValidation="False" CommandName="Delete" Text="Delete" />
<asp:LinkButton ID="NewButton" runat="server" CausesValidation="False" CommandName="New" Text="New" />
</ItemTemplate>
</asp:FormView>
</td>
</tr>
<tr>
<td> </td>
<td>
<asp:SqlDataSource ID="RequestInfoSqlDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:GretnaRealtyConnectionString %>" OldValuesParameterFormatString="original_{0}" SelectCommand="SELECT [Id], [FromAddress], [PropertyAddress], [Phone], [Message], [FName], [LName] FROM [RequestInfo] WHERE (([PropertyAddress] = #PropertyAddress) AND ([PropertyAddress] = #PropertyAddress2))" InsertCommand="INSERT INTO [RequestInfo] ([FName], [LName], [FromAddress], [Phone], [Message],[PropertyAddress]) VALUES (#FName, #LName, #FromAddress, #Phone, #Message, #Hiddenfield1)">
<InsertParameters>
<asp:Parameter Name="FName" />
<asp:Parameter Name="LName" />
<asp:Parameter Name="FromAddress" />
<asp:Parameter Name="Phone" />
<asp:Parameter Name="Message" />
<asp:Parameter Name="Hiddenfield1" />
</InsertParameters>
<SelectParameters>
<asp:ControlParameter ControlID="DetailsView1" Name="PropertyAddress" PropertyName="SelectedValue" Type="String" DefaultValue="0" />
<asp:QueryStringParameter Name="PropertyAddress2" QueryStringField="Paddress" Type="String" />
</SelectParameters>
</asp:SqlDataSource>
</td>
</tr>
</table>
<asp:SqlDataSource ID="DetailsSqlDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:GretnaRealtyConnectionString %>" SelectCommand="SELECT [PID], [PAddress], [City], [St], [Zip], [Price], [Beds], [Bath], [SqFt], [MLS], [Description], [AgentName], [AgentEmail], [Status], [PhotoPath] FROM [GretnaRealty] WHERE ([PID] = #PID)">
<SelectParameters>
<asp:QueryStringParameter Name="PID" QueryStringField="PID" Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>
</asp:Content>
Codebehind:
Imports System.Web.UI.WebControls.GridView
Imports System.Web.UI.WebControls.FormView
Partial Class Details
Inherits System.Web.UI.Page
Protected Sub FormView1_ItemInserted(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.FormViewInsertedEventArgs) Handles FormView1.ItemInserted
Dim MessageTextBox As TextBox = CType(Me.DetailsView1.FindControl("Paddress"), TextBox)
e.Values("MessageTextBox") = DetailsView1.DataItem
Dim Paddresstextbox As TextBox = CType(Me.DetailsView1.FindControl("Paddress"), TextBox)
e.Values("Textbox3") = DetailsView1.DataItem
End Sub
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
'Automatically select the first row for
'the GridView control to cause the
'FormView control to display data.
If Not IsPostBack Then
GridView1.SelectedIndex = 0
End If
End Sub
I may be missing something, but it looks like you do not actually have a control called "PAddress". You have controls bound to the field PAddress, but not a control with the ID "PAddress". That is probably the source of your problem.
When you use the FindControl method of a control, you need to look for the ID of the inner control, not the field to which it is bound.
Similarly, you are looking for a value called "Textbox3" in the e.Values collection. That's where you should be looking for the field name, i.e. e.Values("PropertyAddress").
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()
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.
I have created 2 dropdownlists that are binded to a SQL DB and then pulling up a GridView. But, more specifically is there a way to have 3 user picked boxes and then have a Gridview show up? I would like to have a quick efficient way to do this without problems. I created the first 2 DDLs with autopostback and not working properly. any suggestions?
<asp:Label ID="CustomerNumberLabel" runat="server" Text="Customer Number " Width="125px"></asp:Label>
<asp:DropDownList ID="CustomerNumber" runat="server" AutoPostBack="True"
DataSourceID="ADDRDataSource" DataTextField="SACSNO"
DataValueField="SACSNO" AppendDataBoundItems="True">
<asp:ListItem Text="Select a Customer" Value="" Selected="True" />
</asp:DropDownList><br />
<asp:SqlDataSource ID="ADDRDataSource" runat="server"
ConnectionString="<%$ ConnectionStrings:iSeriesHistoryConnectionString %>"
SelectCommand="SELECT [SACSNO] FROM [ADDR] WHERE ([SARP#1] = #column1)">
<SelectParameters>
<asp:SessionParameter Name="column1" SessionField="userName" Type="Decimal" />
</SelectParameters>
</asp:SqlDataSource>
<asp:Label ID="ShipToNumberLabel" runat="server" Text="Ship-to Location " Width="125px"></asp:Label>
<asp:DropDownList ID="ShipToNumber" runat="server"
DataSourceID="ADDRShipToNumberDataSource" DataTextField="SASHNM"
DataValueField="SASHNM" AutoPostBack="True">
<asp:ListItem Text="Select Ship-To Location" Value="" Selected="True" />
</asp:DropDownList>
<asp:SqlDataSource ID="ADDRShipToNumberDataSource" runat="server"
ConnectionString="<%$ ConnectionStrings:iSeriesHistoryConnectionString %>"
SelectCommand="SELECT [SASHNM], [SASAD1], [SASAD2], [SASCTY], [SACSNO], [SASHST], [SASZIP] FROM [ADDR] WHERE ([SACSNO] = #SACSNO)">
<SelectParameters>
<asp:ControlParameter ControlID="CustomerNumber" Name="SACSNO"
PropertyName="SelectedValue" Type="Decimal" />
</SelectParameters>
</asp:SqlDataSource>
<br /><br />
<asp:FormView ID="FormView1" runat="server"
DataSourceID="ADDRShippingDataSource" Width="400px">
<EditItemTemplate>
SACSNO:
<asp:TextBox ID="SACSNOTextBox" runat="server" Text='<%# Bind("SACSNO") %>' />
<br />
SASHNM:
<asp:TextBox ID="SASHNMTextBox" runat="server" Text='<%# Bind("SASHNM") %>' />
<br />
SASAD1:
<asp:TextBox ID="SASAD1TextBox" runat="server" Text='<%# Bind("SASAD1") %>' />
<br />
SASAD2:
<asp:TextBox ID="SASAD2TextBox" runat="server" Text='<%# Bind("SASAD2") %>' />
<br />
SASCTY:
<asp:TextBox ID="SASCTYTextBox" runat="server" Text='<%# Bind("SASCTY") %>' />
<br />
SASHST:
<asp:TextBox ID="SASHSTTextBox" runat="server" Text='<%# Bind("SASHST") %>' />
<br />
SASZIP:
<asp:TextBox ID="SASZIPTextBox" runat="server" Text='<%# Bind("SASZIP") %>' />
<br />
<asp:LinkButton ID="UpdateButton" runat="server" CausesValidation="True"
CommandName="Update" Text="Update" />
<asp:LinkButton ID="UpdateCancelButton" runat="server"
CausesValidation="False" CommandName="Cancel" Text="Cancel" />
</EditItemTemplate>
<InsertItemTemplate>
SACSNO:
<asp:TextBox ID="SACSNOTextBox" runat="server" Text='<%# Bind("SACSNO") %>' />
<br />
SASHNM:
<asp:TextBox ID="SASHNMTextBox" runat="server" Text='<%# Bind("SASHNM") %>' />
<br />
SASAD1:
<asp:TextBox ID="SASAD1TextBox" runat="server" Text='<%# Bind("SASAD1") %>' />
<br />
SASAD2:
<asp:TextBox ID="SASAD2TextBox" runat="server" Text='<%# Bind("SASAD2") %>' />
<br />
SASCTY:
<asp:TextBox ID="SASCTYTextBox" runat="server" Text='<%# Bind("SASCTY") %>' />
<br />
SASHST:
<asp:TextBox ID="SASHSTTextBox" runat="server" Text='<%# Bind("SASHST") %>' />
<br />
SASZIP:
<asp:TextBox ID="SASZIPTextBox" runat="server" Text='<%# Bind("SASZIP") %>' />
<br />
<asp:LinkButton ID="InsertButton" runat="server" CausesValidation="True"
CommandName="Insert" Text="Insert" />
<asp:LinkButton ID="InsertCancelButton" runat="server"
CausesValidation="False" CommandName="Cancel" Text="Cancel" />
</InsertItemTemplate>
<ItemTemplate>
Customer Detail<br />
<br />
<table class="style1" width="35px">
<tr>
<td class="style2" align="center" >
Address Line 1</td>
<td class="style3" align="center" >
<asp:Label ID="SASAD1Label" runat="server" Text='<%# Bind("SASAD1") %>' />
</td>
</tr>
<tr>
<td class="style2" align="center" >
Address Line 2</td>
<td class="style3" align="center" >
<asp:Label ID="SASAD2Label" runat="server" Text='<%# Bind("SASAD2") %>' />
</td>
</tr>
<tr>
<td class="style2" align="center">
City</td>
<td class="style3" align="center" >
<asp:Label ID="SASCTYLabel" runat="server" Text='<%# Bind("SASCTY") %>' />
</td>
</tr>
<tr>
<td align="center" class="style2">
State</td>
<td class="style3" align="center" >
<asp:Label ID="SASHSTLabel" runat="server" Text='<%# Bind("SASHST") %>' />
</td>
</tr>
<tr>
<td align="center" class="style2">
Zip</td>
<td class="style3" align="center" >
<asp:Label ID="SASZIPLabel" runat="server" Text='<%# Bind("SASZIP") %>' />
</td>
</tr>
</table>
<br />
</ItemTemplate>
</asp:FormView>
<asp:SqlDataSource ID="ADDRShippingDataSource" runat="server"
ConnectionString="<%$ ConnectionStrings:iSeriesHistoryConnectionString %>"
SelectCommand="SELECT [SACSNO], [SASHNM], [SASAD1], [SASAD2], [SASCTY], [SASHST], [SASZIP] FROM [ADDR] WHERE ([SASHNM] = #SASHNM)">
<SelectParameters>
<asp:ControlParameter ControlID="ShipToNumber" Name="SASHNM"
PropertyName="SelectedValue" Type="String" />
</SelectParameters>
</asp:SqlDataSource>
You can turn off AutoPostBack for all the DropDownLists, and add a Button called Lookup with something like the following in the Lookup Button_Click event:
ADDRShippingDataSource.SelectParameters.Clear()
If ShipToNumber.SelectedValue <> "" Then
ADDRShippingDataSource.SelectParameters.Add("SASHNM", ShipToNumber.SelectedValue)
End If
If CustomerNumber.SelectedValue <> "" Then
ADDRShippingDataSource.SelectParameters.Add("SACSNO", CustomerNumber.SelectedValue)
End If
ADDRShippingDataSource.DataBind()
Your select command would need to be updated to include the additional criteria in your DataSource:
SELECT [SACSNO], [SASHNM], [SASAD1], [SASAD2], [SASCTY], [SASHST], [SASZIP] FROM [ADDR] WHERE (#SASHNM IS NULL OR [SASHNM] = #SASHNM) OR (#SACSNO IS NULL OR [SACSNO] = #SACSNO)