Search Queries in VB.net Help Required? - asp.net

I am trying to perform a search query using drop down boxes with a button named search. I want it to bring up the data that is searched for. I dont know where to start from, i have looked around for some coding and different ways to do it but they seem complicated, this is the bit of ASP that is my weakness, need some assistance and guidance. below is the code for the page;
<%# Page Language="VB" MasterPageFile="~/MasterPage.master" AutoEventWireup="false" CodeFile="ForSale.aspx.vb" Inherits="Users_ForSale" title="Properties For Sale" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<h3>Properties For Sale</h3>
<h5>
<asp:Label ID="lblTown" runat="server" Text="Town:"></asp:Label>
<asp:DropDownList ID="ddlTownSearch" runat="server">
<asp:ListItem></asp:ListItem>
<asp:ListItem>Chadderton</asp:ListItem>
<asp:ListItem Value="Failsworth"></asp:ListItem>
<asp:ListItem>Oldham</asp:ListItem>
<asp:ListItem>Royton</asp:ListItem>
<asp:ListItem>Shaw</asp:ListItem>
</asp:DropDownList>
<asp:Label ID="lblBedroomsSearch" runat="server" Text="Bedrooms:"></asp:Label>
<asp:DropDownList ID="DropDownList1" runat="server">
<asp:ListItem></asp:ListItem>
<asp:ListItem>1</asp:ListItem>
<asp:ListItem Value="2"></asp:ListItem>
<asp:ListItem Value="3"></asp:ListItem>
<asp:ListItem>4</asp:ListItem>
<asp:ListItem>5</asp:ListItem>
<asp:ListItem>6+</asp:ListItem>
</asp:DropDownList>
<asp:Label ID="lblMinPrice" runat="server" Text="Min Price (£):"></asp:Label>
<asp:TextBox ID="txtMinPriceSearch" runat="server" Width="87px"></asp:TextBox>
<asp:Label ID="lblMaxPriceSearch" runat="server" style="text-align: left"
Text="Max Price (£):"></asp:Label>
<asp:TextBox ID="TextBox1" runat="server" Width="87px"></asp:TextBox>
</h5>
<h5>
<asp:Button ID="btnForsaleSearch" runat="server" Text="Search" />
</h5>
<p>
<asp:GridView ID="GridView1" runat="server" AllowPaging="True"
AllowSorting="True" AutoGenerateColumns="False" CellPadding="4"
DataKeyNames="ProductId" DataSourceID="SqlDataSource1" ForeColor="#333333"
GridLines="None" Width="588px">
<RowStyle BackColor="#FFFBD6" ForeColor="#333333" />
<Columns>
<asp:ImageField DataImageUrlField="ImageURL">
</asp:ImageField>
<asp:BoundField DataField="ProductId" HeaderText="ProductId" ReadOnly="True"
SortExpression="ProductId" />
<asp:BoundField DataField="Description" HeaderText="Description"
SortExpression="Description" />
<asp:BoundField DataField="Price" HeaderText="Price" SortExpression="Price" />
<asp:BoundField DataField="Town" HeaderText="Town"
SortExpression="Town" />
</Columns>
<FooterStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#FFCC66" ForeColor="#333333" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="Navy" />
<HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="White" />
</asp:GridView>
</p>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:JPEstatesConnectionString %>"
SelectCommand="SELECT * FROM [Products]"
DeleteCommand="DELETE FROM [Products] WHERE [ProductId] = #ProductId"
InsertCommand="INSERT INTO [Products] ([ProductId], [Description], [Price], [Category], [ImageURL]) VALUES (#ProductId, #Description, #Price, #Category, #ImageURL)"
UpdateCommand="UPDATE [Products] SET [Description] = #Description, [Price] = #Price, [Category] = #Category, [ImageURL] = #ImageURL WHERE [ProductId] = #ProductId">
<DeleteParameters>
<asp:Parameter Name="ProductId" Type="String" />
</DeleteParameters>
<UpdateParameters>
<asp:Parameter Name="Description" Type="String" />
<asp:Parameter Name="Price" Type="Decimal" />
<asp:Parameter Name="Category" Type="String" />
<asp:Parameter Name="ImageURL" Type="String" />
<asp:Parameter Name="ProductId" Type="String" />
</UpdateParameters>
<InsertParameters>
<asp:Parameter Name="ProductId" Type="String" />
<asp:Parameter Name="Description" Type="String" />
<asp:Parameter Name="Price" Type="Decimal" />
<asp:Parameter Name="Category" Type="String" />
<asp:Parameter Name="ImageURL" Type="String" />
</InsertParameters>
</asp:SqlDataSource>
</asp:Content>

It depends on your strategy, if you want to search with EXACTLY same matches your search query will be like this:
SELECT * FROM [Products] WHERE [ProductId]=#ProductID AND [Price]=#Price AND...and other conditions that you need.
and if you like to retrieve similar results you have to use LIKE instead of '=' like this one:
SELECT * FROM [Products] WHERE [ProductId] LIKE '%' + #ProductId+ '%' AND ([Price] BETWEEN #Price1 AND #Price2) AND...and other conditions
Price1 and Price2 can be range of user input price
It helps you for using ASP.NET SQLParameters with LIKE statement

Related

Extending the editable box to the end of the detailsview table, using ASP.net

I am currently tasked to do a SQL database with web interface. I am using the Microsoft Visual Web Developer 2010 Express to develop the prototype.
My question is, using the detailsview to edit the user information, how do I make the editable text box to be extended to the end of the table? If possible, the text box can extend downwards with excess text wrapped.
The picture here shows my current output.
Here is my code...
<%# Page Title="Display Staff Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
CodeBehind="DisplayStaff.aspx.cs" Inherits="ASCBioData.About" %>
<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
<h2>
Display Staff Biography
</h2>
<p>
Staff:
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True"
DataSourceID="ObjectDataSource1" DataTextField="Name" DataValueField="ID">
</asp:DropDownList>
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server"
InsertMethod="Insert" OldValuesParameterFormatString="original_{0}"
SelectMethod="GetData"
TypeName="ASCBioData.Data.StaffDataTableAdapters.ASCBioDataTableAdapter">
<InsertParameters>
<asp:Parameter Name="Name" Type="String" />
<asp:Parameter Name="Education" Type="String" />
<asp:Parameter Name="BIO" Type="String" />
<asp:Parameter Name="Highlights" Type="String" />
</InsertParameters>
</asp:ObjectDataSource>
<asp:DetailsView ID="StaffTable" runat="server" AutoGenerateRows="False"
CellPadding="10" DataSourceID="ObjectDataSource2" ForeColor="#333333"
GridLines="None" Height="50px" Width="916px">
<AlternatingRowStyle BackColor="White" />
<CommandRowStyle BackColor="#C5BBAF" Font-Bold="True" HorizontalAlign="Right" />
<EditRowStyle BackColor="#8E8064" Wrap="True" />
<FieldHeaderStyle BackColor="#D0D0D0" Font-Bold="True" VerticalAlign="Top"
Width="70px" />
<Fields>
<asp:BoundField DataField="ID" HeaderText="ID" InsertVisible="False"
ReadOnly="True" SortExpression="ID" Visible="False" />
<asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" />
<asp:BoundField DataField="Education" HeaderText="Education"
SortExpression="Education" />
<asp:BoundField DataField="BIO" HeaderText="BIO" SortExpression="BIO" />
<asp:BoundField DataField="Highlights" HeaderText="Highlights"
SortExpression="Highlights" />
<asp:CommandField ShowEditButton="True" />
</Fields>
<FooterStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
<InsertRowStyle Height="300px" />
<PagerStyle BackColor="#666666" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#E3EAEB" />
</asp:DetailsView>
<asp:ObjectDataSource ID="ObjectDataSource2" runat="server"
InsertMethod="Insert" OldValuesParameterFormatString="original_{0}"
SelectMethod="GetDataByID"
TypeName="ASCBioData.Data.StaffDataTableAdapters.ASCBioDataTableAdapter"
UpdateMethod="UpdateStaffData">
<InsertParameters>
<asp:Parameter Name="Name" Type="String" />
<asp:Parameter Name="Education" Type="String" />
<asp:Parameter Name="BIO" Type="String" />
<asp:Parameter Name="Highlights" Type="String" />
</InsertParameters>
<SelectParameters>
<asp:ControlParameter ControlID="DropDownList1" Name="IsID"
PropertyName="SelectedValue" Type="Int32" />
</SelectParameters>
<UpdateParameters>
<asp:Parameter Name="original_ID" Type="Int32" />
<asp:Parameter Name="Name" Type="String" />
<asp:Parameter Name="Education" Type="String" />
<asp:Parameter Name="BIO" Type="String" />
<asp:Parameter Name="Highlights" Type="String" />
</UpdateParameters>
</asp:ObjectDataSource>
</p>
</asp:Content>
Please advise and thanks in advance...
you can use <asp:TemplateField /> then inside you can use <asp:TextBox /> and set TextMode="MultiLine". So something like
<asp:TemplateField>
<ItemTemplate>
<%# Eval("Highlights") %>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Eval("Highlights") %>'
TextMode="MultiLine"></asp:TextBox>
</EditItemTemplate>
</asp:TemplateField>
This is on top of my head so do test the syntax.. but it should give you what you're looking for.

'Procedure or Function has too many parameters specified'?

I have been searching the web for hours trying to figure out what is causing this exception, I feel like I am missing something...
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
BackColor="White" BorderColor="#999999" BorderStyle="None"
BorderWidth="1px" CellPadding="3" DataKeyNames="ProductID"
DataSourceID="SqlDataSource1"
GridLines="Vertical">
<AlternatingRowStyle BackColor="#DCDCDC" />
<Columns>
<asp:CommandField ShowEditButton="True" />
<asp:BoundField DataField="ProductID" HeaderText="ProductID"
InsertVisible="False" ReadOnly="True" SortExpression="ProductID" />
<asp:BoundField DataField="CategoryID" HeaderText="CategoryID"
SortExpression="CategoryID" />
<asp:BoundField DataField="Title" HeaderText="Title" SortExpression="Title"
/>
<asp:BoundField DataField="ShortDescription" HeaderText="ShortDescription"
SortExpression="ShortDescription" />
<asp:BoundField DataField="LongDescription" HeaderText="LongDescription"
SortExpression="LongDescription" />
<asp:BoundField DataField="ImageUrl" HeaderText="ImageUrl"
SortExpression="ImageUrl" />
<asp:BoundField DataField="Price" HeaderText="Price" SortExpression="Price"
/>
</Columns>
<FooterStyle BackColor="#CCCCCC" ForeColor="Black" />
<HeaderStyle BackColor="#000084" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />
<RowStyle BackColor="#EEEEEE" ForeColor="Black" />
<SelectedRowStyle BackColor="#008A8C" Font-Bold="True" ForeColor="White" />
<SortedAscendingCellStyle BackColor="#F1F1F1" />
<SortedAscendingHeaderStyle BackColor="#0000A9" />
<SortedDescendingCellStyle BackColor="#CAC9C9" />
<SortedDescendingHeaderStyle BackColor="#000065" />
</asp:GridView>
<asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="SqlDataSource2"
DataTextField="Title" DataValueField="CategoryID">
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource2" runat="server"
ConnectionString="<%$ ConnectionStrings:s3435926ConnectionString %>"
SelectCommand="SELECT [CategoryID], [Title] FROM [Category]">
</asp:SqlDataSource>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$
ConnectionStrings:s3435926ConnectionString %>"
SelectCommand="SelectProductsWithParam" SelectCommandType="StoredProcedure"
UpdateCommand="UpdateProdsWithParam" UpdateCommandType="StoredProcedure">
<SelectParameters>
<asp:FormParameter FormField="DropDownList1" Name="prodID" Type="Int32" />
</SelectParameters>
<UpdateParameters>
<asp:Parameter Name="prodID" Type="Int32" />
<asp:Parameter Name="CatID" Type="Int32" />
<asp:Parameter Name="title" Type="String" />
<asp:Parameter Name="Sdesc" Type="String" />
<asp:Parameter Name="Ldesc" Type="String" />
<asp:Parameter Name="url" Type="String" />
<asp:Parameter Name="price" Type="Decimal" />
</UpdateParameters>
</asp:SqlDataSource>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" />
</div>
</form>
</body>
</html>
The SP is
[dbo].[UpdateProdsWithParam] #prodID int, #CatID int, #title nvarchar(50),
#Sdesc nvarchar(100), #Ldesc nvarchar(200),
#url nvarchar(50), #price money
AS
UPDATE Product
SET CategoryID = #CatID, Title = #title,
ShortDescription = #Sdesc, LongDescription = #Ldesc,
ImageUrl = #url, Price = #price
WHERE ProductID = #prodID
I am getting 'Procedure or Function has too many parameters specified'
Any suggestions?
Share your C# code. Error clearly says that you are passing too many parameters. Check out your parameters count & parameters name.

Insert and Search Fields vb.net\asp.net web form to mssql

I've created a page that spits out data from a table. I've gotten the update and delete functionality, but I'm having trouble figuring out how to search and add values. I threw in a few text boxes to mess around with, but I don't know how to make them into controls. I'd like to be able to search the data, as well as enter new data. How do I make these text boxes into search controls for the grid? Also how do I use text boxes or drop down boxes to insert new values into the table?
Here is what I have so far:
<%# Page Title="Bank Statements" Language="VB" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="BankStatements.aspx.vb" Inherits="Compliance.BankStatements" %>
<script runat="server">
Protected Sub Page_Load(sender As Object, e As EventArgs)
End Sub
</script>
<asp:Content runat="server" ID="BodyContent" ContentPlaceHolderID="MainContent">
<hgroup class="title">
<h1><%: Title %>.</h1>
<h2>Enter View and Edit Bank Statments Here<br />
</h2>
</hgroup>
<br />
Franchise ID:
<asp:TextBox ID="TextBox1" runat="server" Width="95px"></asp:TextBox>
Year:
<asp:TextBox ID="TextBox2" runat="server" Width="56px"></asp:TextBox>
Month:
<asp:TextBox ID="TextBox3" runat="server" Width="65px"></asp:TextBox>
<asp:GridView
ID="GridView1"
runat="server"
AllowSorting="True"
AutoGenerateColumns="False"
CellPadding="4"
DataSourceID="SqlDataSource1"
EmptyDataText="There are no data records to display."
ForeColor="#333333"
GridLines="None"
AutoGenerateDeleteButton="True"
AutoGenerateEditButton="True"
EnableSortingAndPagingCallbacks="True"
AllowPaging="True"
>
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:BoundField DataField="FranchiseID" HeaderText="FranchiseID" SortExpression="FranchiseID" />
<asp:BoundField DataField="Year" HeaderText="Year" SortExpression="Year" />
<asp:BoundField DataField="Month" HeaderText="Month" SortExpression="Month" />
<asp:BoundField DataField="Amount" HeaderText="Amount" SortExpression="Amount" />
<asp:BoundField DataField="DatePosted" HeaderText="DatePosted" SortExpression="DatePosted" />
</Columns>
<EditRowStyle BackColor="#7C6F57" />
<FooterStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#666666" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#E3EAEB" />
<SelectedRowStyle BackColor="#C5BBAF" Font-Bold="True" ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#F8FAFA" />
<SortedAscendingHeaderStyle BackColor="#246B61" />
<SortedDescendingCellStyle BackColor="#D4DFE1" />
<SortedDescendingHeaderStyle BackColor="#15524A" />
</asp:GridView>
<hgroup>
</hgroup>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ComplianceConnectionString1 %>"
SelectCommand=
"SELECT FranchiseID, Year, Month, Amount, DatePosted, id FROM BankStmts ORDER BY DatePosted DESC"
DeleteCommand=
"DELETE
FROM [BankStmts]
WHERE id = #id"
UpdateCommand=
"UPDATE [BankStmts]
SET FranchiseID = #FranchiseID, Year = #Year, Month = #Month, Amount = #Amount, DatePosted = #DatePosted
WHERE id = #id"
InsertCommand=
"Insert INTO [BankStmts] FranchiseID, Year, Month, Amount, DatePosted
VALUES #FranchiseID, #Year, #Month, #Amount, #DatePosted"
>
<DeleteParameters>
<asp:Parameter Name="id" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="FranchiseID" />
<asp:Parameter Name="Year" />
<asp:Parameter Name="Month" />
<asp:Parameter Name="Amount" />
<asp:Parameter Name="DatePosted" />
</InsertParameters>
<UpdateParameters>
<asp:Parameter Name="FranchiseID" />
<asp:Parameter Name="Year" />
<asp:Parameter Name="Month" />
<asp:Parameter Name="Amount" />
<asp:Parameter Name="DatePosted" />
<asp:Parameter Name="id" />
</UpdateParameters>
</asp:SqlDataSource>
</asp:Content>

ASP.NET 4.5 GridView and DetailsView

I am trying to work on Chapter 15 exercise from Murach’s ASP.NET 4.5 web programming with C# 2012.
Here is my question.
The webpage has Grid View on the left and Details View on the right.
When I update Ahmed to Ahmad from DetailViews,
the update is not reflected in GridView.
I have to go to the next page and then come back to previous page
in order for the update to display.
I am wondering if there is any solution.
Thank you for your help!
By the way, the code is copied from the book.
<%# Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title>Chapter 15: Customer Maintenance</title>
<link href="Main.css" rel="stylesheet" type="text/css" />
</head>
<body>
<header>
<img src="Images/banner.jpg" "Halloween Store" />
</header>
<section>
<form id="form1" runat="server">
<div id="gridview">
<asp:GridView ID="GridView1" runat="server" AllowPaging="True"
DataKeyNames="Email" DataSourceID="SqlDataSource1"
SelectedIndex="0"
AutoGenerateColumns="False" CellPadding="4" GridLines="None"
ForeColor="Black" Width="320px" >
<Columns>
<asp:BoundField DataField="Email" HeaderText="Email"
ReadOnly="True" Visible="False">
</asp:BoundField>
<asp:BoundField DataField="LastName" HeaderText="LastName">
<HeaderStyle HorizontalAlign="Left" />
<ItemStyle Width="150px" />
</asp:BoundField>
<asp:BoundField DataField="FirstName" HeaderText="FirstName">
<HeaderStyle HorizontalAlign="Left" />
<ItemStyle Width="120px" />
</asp:BoundField>
<asp:CommandField ButtonType="Button" ShowSelectButton="True" />
</Columns>
<HeaderStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
<RowStyle BackColor="White" ForeColor="Black" />
<AlternatingRowStyle BackColor="#E3EAEB" ForeColor="Black" />
<SelectedRowStyle BackColor="#F46D11" ForeColor="White" />
<PagerSettings Mode="NextPreviousFirstLast" />
<PagerStyle BackColor="#1C5E55" ForeColor="White"
HorizontalAlign="Center" />
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:HalloweenConnectionString %>"
OldValuesParameterFormatString ="original_{0}"
ConflictDetection="CompareAllValues"
DeleteCommand="DELETE FROM [Customers]
WHERE [Email] = #original_Email
AND [LastName] = #original_LastName
AND [FirstName] = #original_FirstName
AND [Address] = #original_Address
AND [City] = #original_City
AND [State] = #original_State
AND [ZipCode] = #original_ZipCode
AND [PhoneNumber] = #original_PhoneNumber"
InsertCommand="INSERT INTO [Customers] ([Email], [LastName], [FirstName], [Address], [City], [State], [ZipCode], [PhoneNumber])
VALUES (#Email, #LastName, #FirstName, #Address, #City, #State, #ZipCode, #PhoneNumber)"
SelectCommand="SELECT [Email], [LastName], [FirstName], [Address], [City], [State], [ZipCode], [PhoneNumber]
FROM [Customers] WHERE ([Email] = #Email)"
UpdateCommand="UPDATE [Customers] SET [Email] = #Email,
[LastName] = #LastName,
[FirstName]= #FirstName,
[Address] = #Address, [City] = #City, [State] = #State, [ZipCode] = #ZipCode,
[PhoneNumber] = #PhoneNumber
WHERE [Email] = #original_Email
AND [LastName] = #original_LastName
AND [FirstName] = #original_FirstName
AND [Address] = #original_Address AND [City] = #original_City AND [State] = #original_State AND [ZipCode] = #original_ZipCode
AND [PhoneNumber] = #original_PhoneNumber">
<SelectParameters>
<asp:ControlParameter ControlID="GridView1" Name="Email" PropertyName="SelectedValue" Type="String"/>
</SelectParameters>
<DeleteParameters>
<asp:Parameter Name="original_Email" Type="String" />
<asp:Parameter Name="original_LastName" Type="String" />
<asp:Parameter Name="original_FirstName" Type="String" />
<asp:Parameter Name="original_Address" Type="String" />
<asp:Parameter Name="original_City" Type="String" />
<asp:Parameter Name="original_State" Type="String" />
<asp:Parameter Name="original_ZipCode" Type="String" />
<asp:Parameter Name="original_PhoneNumber" Type="String" />
</DeleteParameters>
<UpdateParameters>
<asp:Parameter Name="Email" Type="String" />
<asp:Parameter Name="LastName" Type="String" />
<asp:Parameter Name="FirstName" Type="String" />
<asp:Parameter Name="Address" Type="String" />
<asp:Parameter Name="City" Type="String" />
<asp:Parameter Name="State" Type="String" />
<asp:Parameter Name="ZipCode" Type="String" />
<asp:Parameter Name="PhoneNumber" Type="String" />
<asp:Parameter Name="original_Email" Type="String" />
<asp:Parameter Name="original_LastName" Type="String" />
<asp:Parameter Name="original_FirstName" Type="String" />
<asp:Parameter Name="original_Address" Type="String" />
<asp:Parameter Name="original_City" Type="String" />
<asp:Parameter Name="original_State" Type="String" />
<asp:Parameter Name="original_ZipCode" Type="String" />
<asp:Parameter Name="original_PhoneNumber" Type="String" />
</UpdateParameters>
<InsertParameters>
<asp:Parameter Name="Email" Type="String" />
<asp:Parameter Name="LastName" Type="String" />
<asp:Parameter Name="FirstName" Type="String" />
<asp:Parameter Name="Address" Type="String" />
<asp:Parameter Name="City" Type="String" />
<asp:Parameter Name="State" Type="String" />
<asp:Parameter Name="ZipCode" Type="String" />
<asp:Parameter Name="PhoneNumber" Type="String" />
</InsertParameters>
</asp:SqlDataSource>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:HalloweenConnectionString %>"
SelectCommand="SELECT [Email], [LastName], [FirstName]
FROM [Customers] ORDER BY [LastName]">
</asp:SqlDataSource>
</div>
<div id="detailsview">
<asp:DetailsView ID="DetailsView1" runat="server" Height="50px" Width="363px" AutoGenerateRows="False" DataKeyNames="Email" DataSourceID="SqlDataSource2" style="margin-left: 0px">
<Fields>
<asp:TemplateField HeaderText="Email">
<ItemTemplate>
<asp:Label ID="lblEmailIT" runat="server" Text='<%# Bind("Email") %>'>
</asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="lblEmailET" runat="server" Text='<%# Bind("Email") %>'>
</asp:TextBox>
</EditItemTemplate>
<InsertItemTemplate>
<asp:TextBox ID="txtEmailInT" runat="server" Text='<%# Bind("Email") %>'>
</asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="txtEmailInT" ErrorMessage="Email is a required field.">
</asp:RequiredFieldValidator>
</InsertItemTemplate>
<HeaderStyle HorizontalAlign="Left" Width="100px" />
<ItemStyle Width="200px" />
</asp:TemplateField>
<asp:TemplateField HeaderText="LastName">
<ItemTemplate>
<asp:Label ID="lblLastNameIT" runat="server" Text='<%# Bind("LastName") %>'>
</asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="lblLastNameET" runat="server" Text='<%# Bind("LastName") %>'>
</asp:TextBox>
</EditItemTemplate>
<InsertItemTemplate>
<asp:TextBox ID="lblLastNameInT" runat="server" Text='<%# Bind("LastName") %>'>
</asp:TextBox>
</InsertItemTemplate>
<HeaderStyle HorizontalAlign="Left" Width="100px" />
<ItemStyle Width="200px" />
</asp:TemplateField>
<asp:TemplateField HeaderText="FirstName">
<ItemTemplate>
<asp:Label ID="lblFirstNameIT" runat="server" Text='<%# Bind("FirstName") %>'>
</asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="lblFirstNameET" runat="server" Text='<%# Bind("FirstName") %>'>
</asp:TextBox>
</EditItemTemplate>
<InsertItemTemplate>
<asp:TextBox ID="lblFirstNameInT" runat="server" Text='<%# Bind("FirstName") %>'>
</asp:TextBox>
</InsertItemTemplate>
<HeaderStyle HorizontalAlign="Left" Width="100px" />
<ItemStyle Width="200px" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Address">
<ItemTemplate>
<asp:Label ID="lblAddressIT" runat="server" Text='<%# Bind("Address") %>'>
</asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="lblAddressET" runat="server" Text='<%# Bind("Address") %>'>
</asp:TextBox>
</EditItemTemplate>
<InsertItemTemplate>
<asp:TextBox ID="lblAddressInT" runat="server" Text='<%# Bind("Address") %>'>
</asp:TextBox>
</InsertItemTemplate>
<HeaderStyle HorizontalAlign="Left" Width="100px" />
<ItemStyle Width="200px" />
</asp:TemplateField>
<asp:TemplateField HeaderText="City">
<ItemTemplate>
<asp:Label ID="lblCityIT" runat="server" Text='<%# Bind("City") %>'>
</asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="lblCityET" runat="server" Text='<%# Bind("City") %>'>
</asp:TextBox>
</EditItemTemplate>
<InsertItemTemplate>
<asp:TextBox ID="lblCityInT" runat="server" Text='<%# Bind("City") %>'>
</asp:TextBox>
</InsertItemTemplate>
<HeaderStyle HorizontalAlign="Left" Width="100px" />
<ItemStyle Width="200px" />
</asp:TemplateField>
<asp:TemplateField HeaderText="State">
<ItemTemplate>
<asp:Label ID="lblStateIT" runat="server" Text='<%# Bind("State") %>'>
</asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="lblStateET" runat="server" Text='<%# Bind("State") %>'>
</asp:TextBox>
</EditItemTemplate>
<InsertItemTemplate>
<asp:TextBox ID="lblStateInT" runat="server" Text='<%# Bind("State") %>'>
</asp:TextBox>
</InsertItemTemplate>
<HeaderStyle HorizontalAlign="Left" Width="100px" />
<ItemStyle Width="200px" />
</asp:TemplateField>
<asp:TemplateField HeaderText="ZipCode">
<ItemTemplate>
<asp:Label ID="lblZipCodeIT" runat="server" Text='<%# Bind("ZipCode") %>'>
</asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="lblZipCodeET" runat="server" Text='<%# Bind("ZipCode") %>'>
</asp:TextBox>
</EditItemTemplate>
<InsertItemTemplate>
<asp:TextBox ID="lblZipCodeInT" runat="server" Text='<%# Bind("ZipCode") %>'>
</asp:TextBox>
</InsertItemTemplate>
<HeaderStyle HorizontalAlign="Left" Width="100px" />
<ItemStyle Width="200px" />
</asp:TemplateField>
<asp:TemplateField HeaderText="PhoneNumber">
<ItemTemplate>
<asp:Label ID="lblPhoneNumberIT" runat="server" Text='<%# Bind("PhoneNumber") %>'>
</asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="lblPhoneNumberET" runat="server" Text='<%# Bind("PhoneNumber") %>'>
</asp:TextBox>
</EditItemTemplate>
<InsertItemTemplate>
<asp:TextBox ID="lblPhoneNumberInT" runat="server" Text='<%# Bind("PhoneNumber") %>'>
</asp:TextBox>
</InsertItemTemplate>
<HeaderStyle HorizontalAlign="Left" Width="100px" />
<ItemStyle Width="200px" />
</asp:TemplateField>
<asp:CommandField ButtonType="Button" ShowDeleteButton="true" ShowEditButton="true" ShowInsertButton="true" />
</Fields>
</asp:DetailsView>
<asp:ValidationSummary ID="ValidationSummary1" runat="server"
HeaderText="Please correct the following errors:" CssClass="error" />
<p>
<asp:Label ID = "lblError" runat="server" EnableViewState="False" CssClass="error">
</asp:Label>
</p>
</div>
</form>
</section>
</body>
</html>
Yes, in your behind code under the Page_Load method insert
if(!Page.IsPostBack)
{
GridView1.DataBind();
}
You have to use this event into this event you can bind the Gridview and to redirect the the same page your data will be reflected on your Gridview
Hope this will help try this....
protected void DetailsView1_ItemUpdated(object sender, DetailsViewUpdatedEventArgs e)
{
if (e.AffectedRows == 1)
{
GridView1.DataBind();
Response.Redirect("Yourpage.aspx");
}
}

how to align images in a gridview control next to each other

i have some images uploaded and their path in the database and add a template column of image and it show up fine but the images show on top of each other here is my code:
<asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False"
DataKeyNames="id" DataSourceID="SqlDataSource2"
EmptyDataText="There are no data records to display." BorderStyle="None">
<Columns>
<asp:BoundField DataField="id" HeaderText="id" ReadOnly="True"
SortExpression="id" Visible="False" />
<asp:TemplateField ShowHeader="False">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Eval("img") %>'
Tooltip='<%# Eval("img") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<div style="height:90px;white-space:nowrap;display:inline;">
<img id="photoAlbumPhotos" class="photoAlbumPhotos" runat="server" alt="Image Not Found" src='<%# Eval("img") %>' />
</div>
</ItemTemplate>
<ControlStyle BorderStyle="None" />
<ControlStyle BorderStyle="None" cssclass="test"></ControlStyle>
<HeaderStyle BorderStyle="None" />
<ItemStyle BorderStyle="None" HorizontalAlign="Left" Wrap="False"
CssClass="test" />
</asp:TemplateField>
</Columns>
<RowStyle Wrap="False" />
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource2" runat="server"
ConnectionString="<%$ ConnectionStrings:testConnectionString1 %>"
DeleteCommand="DELETE FROM [img] WHERE [id] = #id"
InsertCommand="INSERT INTO [img] ([img]) VALUES (#img)"
ProviderName="<%$ ConnectionStrings:testConnectionString1.ProviderName %>"
SelectCommand="SELECT [id], [img] FROM [img]"
UpdateCommand="UPDATE [img] SET [img] = #img WHERE [id] = #id">
<DeleteParameters>
<asp:Parameter Name="id" Type="Int32" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="img" Type="String" />
</InsertParameters>
<UpdateParameters>
<asp:Parameter Name="img" Type="String" />
<asp:Parameter Name="id" Type="Int32" />
</UpdateParameters>
</asp:SqlDataSource>
i tried image float:left,dispaly:inline,inline-block but no luck
i am using asp.net 4.0
thanks
This is the normal behavior for a GridView. You can achieve a side by side rendering using the ListView and the GroupTemplate property:
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.listview.grouptemplate.aspx

Resources