how to align images in a gridview control next to each other - asp.net

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

Related

Freeze Gridview header

I would like the header frozen at the top because i have over 9000 rows. I have tried "fixed" but that doesn't look the best. It was fixed in place on scroll but looked like it was floating in place. What can i do to get the top frozen? I tried a css style but it wasn't freezing the header either. If i can get the header frozen the next step is to freeze the footer on screen also so new entries can be made without having to go to the bottom on 9000 rows.
<asp:GridView id="myGridView" runat="server" AutoGenerateColumns="False"
CssClass="Grid"
Overflow="auto"
AllowSorting="False"
CellPadding="4"
ForeColor="#333333"
GridLines="None"
ShowFooter="True"
DataKeyNames="RMANumber" width="99%">
<AlternatingRowStyle BackColor="LightGray" />
<Columns>
<asp:TemplateField HeaderText="RMA Number" HeaderStyle-VerticalAlign="Middle" HeaderStyle-HorizontalAlign="Left">
<ItemTemplate>
<asp:Label id="lblRMANumber" runat="server" ReadOnly="false" Text='<%# DataBinder.Eval(Container, "DataItem.RMANumber") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox id="txtEditRMANumber" size="16" runat="server" ReadOnly="false" Text='<%# DataBinder.Eval(Container, "DataItem.RMANumber") %>'></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox id="txtAddRMANumber" size="16" runat="server"></asp:TextBox>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Decon Form? Y/N" HeaderStyle-VerticalAlign="Middle" HeaderStyle-HorizontalAlign="Left">
<ItemTemplate>
<asp:Label id="lblDeconForm" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.DeconForm") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox id="txtEditDeconForm" size="16" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.DeconForm") %>'></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox id="txtAddDeconForm" size="16" runat="server"></asp:TextBox>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Customer" HeaderStyle-VerticalAlign="Middle" HeaderStyle-HorizontalAlign="Left">
<ItemTemplate>
<asp:Label id="lblCustomer" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.Customer") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox id="txtEditCustomer" size="16" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.Customer") %>'></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox id="txtAddCustomer" size="16" runat="server"></asp:TextBox>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Problem / Solution Found" HeaderStyle-VerticalAlign="Middle" HeaderStyle-HorizontalAlign="Left">
<ItemTemplate>
<asp:Label id="lblProblemSolutionFound" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.ProblemSolutionFound") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox id="txtEditProblemSolutionFound" size="16" runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.ProblemSolutionFound") %>'></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox id="txtAddProblemSolutionFound" size="16" runat="server"></asp:TextBox>
<asp:Button id="btnAdd" runat="server" Text="Add" CommandName="Add" AutoPostBack="False" ></asp:Button>
</FooterTemplate>
</asp:TemplateField>
<asp:CommandField ShowEditButton="True" CancelText="Cancel" DeleteText="Delete" EditText="Edit" UpdateText="Update" HeaderText="Modify"
ShowDeleteButton="False" HeaderStyle-VerticalAlign="Middle" HeaderStyle-HorizontalAlign="Left"
ButtonType="Image" CancelImageUrl="Images/Cancel.png" EditImageUrl="Images/Edit.png" UpdateImageUrl="Images/Update.png" ControlStyle-Width="60" ControlStyle-Height="20"/>
<asp:TemplateField HeaderText="Delete" ShowHeader="true" HeaderStyle-VerticalAlign="Middle" HeaderStyle-HorizontalAlign="Left" >
<ItemTemplate>
<asp:ImageButton ID="DeleteButton" runat="server" ImageUrl="Images/Delete.png" Width="60" Height="20" VerticalAlign="Center"
CommandName="Delete"
AlternateText="Delete" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
<EditRowStyle BackColor="#ADD8E6" />
<FooterStyle BackColor="#ADD8E6" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#EFF3FB" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#F5F7FB" />
<SortedAscendingHeaderStyle BackColor="#6D95E1" />
<SortedDescendingCellStyle BackColor="#E9EBEF" />
<SortedDescendingHeaderStyle BackColor="#4870BE" />
</asp:GridView>
To keep the header at the top i used a script to duplicate the header and put it in it's own container. But I still had issues with the footer being visible. I decided to make a create button in a new page instead of dealing with the footer. It is much more cleaner for the user inputting data into a form instead of gridview footer. In the same fashion i use the edit record button to open the record in a new page for updating / editing it. I also made the gridview page sort by desc to only see the most recent RMAs, removed the duplicate header script, and used paging. no reason to see all the records, just the most recent.
<asp:GridView ID="GridView1" runat="server"
AllowPaging="True"
PageSize="10"
AllowSorting="True"
AutoGenerateColumns="False"
DataKeyNames="RMANumber"
CellPadding="1"
ForeColor="#333333"
DataSourceID="SqlDataSource1">
<AlternatingRowStyle BackColor="LightGray" />
<Columns>
<asp:CommandField ShowDeleteButton="False" ShowEditButton="True" HeaderStyle-VerticalAlign="Middle" HeaderStyle-HorizontalAlign="Left"
ButtonType="Image" CancelImageUrl="Images/Cancel.png"
EditImageUrl="Images/Edit.png" UpdateImageUrl="Images/Update.png"
ControlStyle-Width="60" ControlStyle-Height="20">
<ControlStyle Height="20px" Width="60px"></ControlStyle>
<HeaderStyle HorizontalAlign="Left" VerticalAlign="Middle"></HeaderStyle>
</asp:CommandField>
<asp:Boundfield DataField="RMANumber" HeaderText="RMA Number" ReadOnly="True" SortExpression="RMANumber" > <ItemStyle Width="5%" /> </asp:Boundfield>
<asp:BoundField DataField="DconForm" HeaderText="Dcon Form" SortExpression="DconForm" > <ItemStyle Width="3%" /> </asp:BoundField>
<asp:BoundField DataField="Customer" HeaderText="Customer" SortExpression="Customer" > <ItemStyle Width="10%" /> </asp:BoundField>
<asp:BoundField DataField="ItemBeingReturned" HeaderText="Item(s) Being Returned" SortExpression="ItemBeingReturned" > <ItemStyle Width="10%" /> </asp:BoundField>
<asp:BoundField DataField="ReasonForReturn" HeaderText="Reason For Return" SortExpression="ReasonForReturn" > <ItemStyle Width="15%" /> </asp:BoundField>
<asp:BoundField DataField="Dia" HeaderText="Dia" SortExpression="Dia" > <ItemStyle Width="7%" /> </asp:BoundField>
<asp:BoundField DataField="RMADate" HeaderText="RMA Date" SortExpression="RMADate" > <ItemStyle Width="5%" /> </asp:BoundField>
<asp:BoundField DataField="ReturnedDate" HeaderText="Returned Date" SortExpression="ReturnedDate" > <ItemStyle Width="5%" /> </asp:BoundField>
<asp:BoundField DataField="DateShipped" HeaderText="Date Shipped" SortExpression="DateShipped" > <ItemStyle Width="5%" /> </asp:BoundField>
<asp:BoundField DataField="Status" HeaderText="Status" SortExpression="Status" > <ItemStyle Width="5%" /> </asp:BoundField>
<asp:BoundField DataField="PIKEContact" HeaderText="PIKE Contact" SortExpression="PIKEContact" > <ItemStyle Width="7%" /> </asp:BoundField>
<asp:BoundField DataField="DiamondResults" HeaderText="Diamond Results" SortExpression="DiamondResults" > <ItemStyle Width="5%" /> </asp:BoundField>
<asp:BoundField DataField="ProblemSolutionFound" HeaderText="Problem / Solution Found" SortExpression="ProblemSolutionFound" > <ItemStyle Width="15%" /> </asp:BoundField>
<asp:TemplateField HeaderText="" ShowHeader="true" HeaderStyle-VerticalAlign="Middle" HeaderStyle-HorizontalAlign="Left" >
<ItemTemplate>
<asp:ImageButton ID="DeleteButton" runat="server" ImageUrl="Images/Delete.png" Width="60" Height="20" VerticalAlign="Center"
CommandName="Delete"
AlternateText="Delete" />
</ItemTemplate>
<HeaderStyle HorizontalAlign="Left" VerticalAlign="Middle"></HeaderStyle>
</asp:TemplateField>
</Columns>
<EditRowStyle BackColor="#ADD8E6" />
<FooterStyle BackColor="#ADD8E6" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#EFF3FB" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#F5F7FB" />
<SortedAscendingHeaderStyle BackColor="#6D95E1" />
<SortedDescendingCellStyle BackColor="#E9EBEF" />
<SortedDescendingHeaderStyle BackColor="#4870BE" />
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:PIKE_Intranet_DBConnectionString %>"
DeleteCommand="DELETE FROM [RMATable] WHERE [RMANumber] = #RMANumber"
InsertCommand="INSERT INTO [RMATable] ([RMANumber], [DconForm], [Customer], [ItemBeingReturned], [ReasonForReturn], [Dia], [RMADate], [ReturnedDate], [DateShipped], [Status], [PIKEContact], [DiamondResults], [ProblemSolutionFound]) VALUES (#RMANumber, #DconForm, #Customer, #ItemBeingReturned, #ReasonForReturn, #Dia, #RMADate, #ReturnedDate, #DateShipped, #Status, #PIKEContact, #DiamondResults, #ProblemSolutionFound)"
SelectCommand="SELECT * FROM [RMATable] ORDER BY [RMANumber] DESC"
UpdateCommand="UPDATE [RMATable] SET [DconForm] = #DconForm, [Customer] = #Customer, [ItemBeingReturned] = #ItemBeingReturned, [ReasonForReturn] = #ReasonForReturn, [Dia] = #Dia, [RMADate] = #RMADate, [ReturnedDate] = #ReturnedDate, [DateShipped] = #DateShipped, [Status] = #Status, [PIKEContact] = #PIKEContact, [DiamondResults] = #DiamondResults, [ProblemSolutionFound] = #ProblemSolutionFound WHERE [RMANumber] = #RMANumber">
<DeleteParameters>
<asp:Parameter Name="RMANumber" Type="String" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="RMANumber" Type="String" />
<asp:Parameter Name="DconForm" Type="String" />
<asp:Parameter Name="Customer" Type="String" />
<asp:Parameter Name="ItemBeingReturned" Type="String" />
<asp:Parameter Name="ReasonForReturn" Type="String" />
<asp:Parameter Name="Dia" Type="String" />
<asp:Parameter Name="RMADate" Type="String" />
<asp:Parameter Name="ReturnedDate" Type="String" />
<asp:Parameter Name="DateShipped" Type="String" />
<asp:Parameter Name="Status" Type="String" />
<asp:Parameter Name="PIKEContact" Type="String" />
<asp:Parameter Name="DiamondResults" Type="String" />
<asp:Parameter Name="ProblemSolutionFound" Type="String" />
</InsertParameters>
<UpdateParameters>
<asp:Parameter Name="DconForm" Type="String" />
<asp:Parameter Name="Customer" Type="String" />
<asp:Parameter Name="ItemBeingReturned" Type="String" />
<asp:Parameter Name="ReasonForReturn" Type="String" />
<asp:Parameter Name="Dia" Type="String" />
<asp:Parameter Name="RMADate" Type="String" />
<asp:Parameter Name="ReturnedDate" Type="String" />
<asp:Parameter Name="DateShipped" Type="String" />
<asp:Parameter Name="Status" Type="String" />
<asp:Parameter Name="PIKEContact" Type="String" />
<asp:Parameter Name="DiamondResults" Type="String" />
<asp:Parameter Name="ProblemSolutionFound" Type="String" />
<asp:Parameter Name="RMANumber" Type="String" />
</UpdateParameters>
</asp:SqlDataSource>
<br />
</div>
</form>

How can I show an dropdown menu when update is clicked in gridview?

I have a field named status in my gridview i want it like that so that when user clickes update on gridview in the place of textfield there will be an dropdown with published and unpublished option.here is the code
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False" DataKeyNames="Id" DataSourceID="SqlDataSource3">
<Columns>
<asp:CommandField ShowDeleteButton="True" ShowEditButton="True" />
<asp:BoundField DataField="name" HeaderText="name" SortExpression="name" />
<asp:BoundField DataField="info" HeaderText="info" SortExpression="info" />
<asp:BoundField DataField="productcode" HeaderText="productcode" SortExpression="productcode" />
<asp:BoundField DataField="status" HeaderText="status" SortExpression="status" />
<asp:BoundField DataField="price" HeaderText="price" SortExpression="price" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource3" runat="server" ConnectionString="<%$ ConnectionStrings:DefaultConnection %>" DeleteCommand="DELETE FROM [product_tbl] WHERE [Id] = #Id" InsertCommand="INSERT INTO [product_tbl] ([Id], [subcat], [name], [info], [brandid], [gender]) VALUES (#Id, #subcat, #name, #info, #brandid, #gender)" SelectCommand="SELECT * FROM [product_tbl]" UpdateCommand="UPDATE [product_tbl] SET [subcat] = #subcat, [name] = #name, [info] = #info, [brandid] = #brandid, [productcode] = #productcode, [gender] = #gender WHERE [Id] = #Id">
<DeleteParameters>
<asp:Parameter Name="Id" Type="Int32" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="Id" Type="Int32" />
<asp:Parameter Name="subcat" Type="Int32" />
<asp:Parameter Name="name" Type="String" />
<asp:Parameter Name="info" Type="String" />
<asp:Parameter Name="brandid" Type="Int32" />
<asp:Parameter Name="gender" Type="Int32" />
</InsertParameters>
<UpdateParameters>
<asp:Parameter Name="subcat" Type="Int32" />
<asp:Parameter Name="name" Type="String" />
<asp:Parameter Name="info" Type="String" />
<asp:Parameter Name="brandid" Type="Int32" />
<asp:Parameter Name="productcode" Type="Int32" />
<asp:Parameter Name="gender" Type="Int32" />
<asp:Parameter Name="Id" Type="Int32" />
</UpdateParameters>
</asp:SqlDataSource>
For dropdown list you need to place templatefield
<asp:TemplateField HeaderText="Status">
<EditItemTemplate>
<asp:DropDownList ID="ddlStautus" runat="server">
<asp:ListItem>published</asp:ListItem>
<asp:ListItem>unpublished</asp:ListItem>
</asp:DropDowList>
</asp:TempLateFeild>
and bind your gridview on code behind
for more reference use This link
OR
<asp:GridView ID="GridView1" runat="server" CellPadding="4" DataKeyNames="UserID"
ForeColor="#333333" GridLines="None"
AutoGenerateColumns="False" onrowediting="GridView1_RowEditing" onrowupdating="GridView1_RowUpdating1"
onrowcancelingedit="GridView1_RowCancelingEdit"
onrowdatabound="GridView1_RowDataBound1"
onrowdeleting="GridView1_RowDeleting">
<Columns>
<asp:TemplateField HeaderText="id" Visible="False">
<ItemTemplate>
<asp:Label ID="lblID" runat="server" Text='<%# Bind("ID") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Name">
<EditItemTemplate>
<asp:TextBox ID="txtName" runat="server" Width="75px"
Text='<%# Bind("Name") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="lblName" runat="server"
Text='<%# Bind("Name") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Info">
<EditItemTemplate>
<asp:TextBox ID="txtInfo" runat="server" Width="75px"
Text='<%# Bind("Info") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="lblInfo" runat="server"
Text='<%# Bind("Info") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="productcode">
<EditItemTemplate>
<asp:TextBox ID="txtproductcode" runat="server" Width="75px"
Text='<%# Bind("DomainID") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="lblproductcode" runat="server"
Text='<%# Bind("productcode") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText = "status">
<ItemTemplate>
<asp:Label ID="lblRole" runat="server" Text='<%# Bind("status") %>' Visible="false"/>
<asp:DropDownList ID="ddlRole" runat="server">
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
<asp:CommandField ShowEditButton="True"/>
<asp:TemplateField HeaderText="Delete?">
<ItemTemplate>
<span onclick="return confirm('Are you sure to Delete the record?')">
<asp:LinkButton ID="lnkB" runat="Server" Text="Delete" CommandName="Delete"></asp:LinkButton>
</span>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
and on code behind use code which is given in the link

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");
}
}

ASP gridview not updating database

When I click Edit on a row in the gridview, it shows the data like it should. It shows the text boxes where I expect to see them and it allows me to modify the data in the box. When I click Update on that row it does the same thing as cancel; the page refills without saving any data changes. The database is also unchanged.
<%# Page Title="Employee Lookup"Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeBehind="EmployeeLookup.aspx.cs" Inherits="WSC.EmployeeLookup" %>
<p>
<asp:Table ID="Table1" runat="server" CellPadding="5" Width="442px">
<asp:TableRow>
<asp:TableCell><asp:Button ID="NewUserButton" PostBackUrl="~/EmployeeInfo.aspx" runat="server" Text="New Employee" /></asp:TableCell>
</asp:TableRow>
</asp:Table>
</p>
<p>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="eID"
AutoGenerateEditButton="True" DataSourceID="AccessDataSource2"
EmptyDataText="There are no data records to display." AllowSorting="True" AllowPaging="True">
<Columns>
<asp:BoundField DataField="eID" HeaderText="Employee ID" ReadOnly="True" SortExpression="eID" />
<asp:BoundField DataField="eFirstName" HeaderText="FirstName" SortExpression="eFirstName" />
<asp:BoundField DataField="eLastName" HeaderText="LastName" SortExpression="eLastName" />
<asp:TemplateField HeaderText="JobTitle" SortExpression="eJobTitle">
<EditItemTemplate>
<asp:TextBox ID="TextBox4" width="50" runat="server" Text='<%# Bind("eJobTitle") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label4" runat="server" Text='<%# Eval("eJobTitle") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Dept Code" SortExpression="deptNumber">
<EditItemTemplate>
<asp:TextBox ID="TextBox5" width="50" runat="server" Text='<%# Bind("deptNumber") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label5" runat="server" Text='<%# Eval("deptNumber") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="UserName" SortExpression="eUserName">
<EditItemTemplate>
<asp:TextBox ID="TextBox6" width="50" runat="server" Text='<%# Bind("eUserName") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label6" runat="server" Text='<%# Eval("eUserName") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Password" SortExpression="ePassword">
<EditItemTemplate>
<asp:TextBox ID="TextBox3" width="70" runat="server" Text='<%# Bind("ePassword") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label3" runat="server" Text="*********"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Email" SortExpression="eEmail">
<EditItemTemplate>
<asp:TextBox ID="TextBox7" runat="server" Text='<%# Bind("eEmail") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label7" runat="server" Text='<%# Eval("eEmail") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Hire Date" SortExpression="eDateHire">
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("eDateHire") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Eval("eDateHire") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="securityID" SortExpression="securityID">
<EditItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Bind("securityID") %>'></asp:Label>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Eval("securityID") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:Label ID="ErrorMessageLabel" runat="server" Text="" ></asp:Label>
<asp:AccessDataSource ID="AccessDataSource2" runat="server" DataFile="C:\WSC\WSC\WSC\CIS470_Database.accdb"
SelectCommand="SELECT `eID`, `eFirstName`, `eLastName`, `eJobTitle`, `deptNumber`, `eUserName`, `ePassword`, `eEmail`, `eDateHire`, `securityID` FROM `Employee`"
UpdateCommand="UPDATE `Employee` SET `eFirstName` = ?, `eLastName` = ?, `eJobTitle` = ?, `deptNumber` = ?, `eUserName` = ?, `ePassword` = ?, `eEmail` = ?, `eDateHire` = ?, `securityID` = ? WHERE `eID` = ?">
<DeleteParameters>
<asp:Parameter Name="eID" Type="Int32" />
</DeleteParameters>
<UpdateParameters>
<asp:Parameter Name="eFirstName" Type="String" />
<asp:Parameter Name="eLastName" Type="String" />
<asp:Parameter Name="eJobTitle" Type="String" />
<asp:Parameter Name="deptNumber" Type="String" />
<asp:Parameter Name="eUserName" Type="String" />
<asp:Parameter Name="ePassword" Type="String" />
<asp:Parameter Name="eEmail" Type="String" />
<asp:Parameter Name="ePhone" Type="String" />
<asp:Parameter Name="eDateHire" Type="DateTime" />
<asp:Parameter Name="eDateTerm" Type="DateTime" />
<asp:Parameter Name="securityID" Type="Int32" />
</UpdateParameters>
</asp:AccessDataSource>
</p>
Add:
<asp:Parameter Name="eID" Type="Int32" />
To:
<UpdateParameters>
<asp:Parameter Name="eFirstName" Type="String" />
<asp:Parameter Name="eLastName" Type="String" />
<asp:Parameter Name="eJobTitle" Type="String" />
<asp:Parameter Name="deptNumber" Type="String" />
<asp:Parameter Name="eUserName" Type="String" />
<asp:Parameter Name="ePassword" Type="String" />
<asp:Parameter Name="eEmail" Type="String" />
<asp:Parameter Name="ePhone" Type="String" />
<asp:Parameter Name="eDateHire" Type="DateTime" />
<asp:Parameter Name="eDateTerm" Type="DateTime" />
<asp:Parameter Name="securityID" Type="Int32" />
</UpdateParameters>
And use:
eFirstName = #eFirstName, ... WHERE eID = #eID"
instead of what you are using in your UpdateCommand. The problem is you parameters must start with # in your update and deletecommand. Then they will much the parameters between
<DeleteParameters></DeleteParameters>
And
<UpdateParameters></UpdateParameters>

Search Queries in VB.net Help Required?

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

Resources