Freeze Gridview header - asp.net

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>

Related

'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.

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

Insert row to SQL Server using Visual Studio 2010 and ASP.NET

Alright I have a question that seems simple but I haven't been able to figure it out.
Just some quick details: I am using Visual Studio 2010 with ASP.NET, VB, and using SQL Server as my database
I am creating a website using ASP.NET and I have a mailing list database, I have a add to mailing list page that takes in certain fields (Name, e-mail, phone number) that are TextBox and a sumbit button. When the submit button is clicked how to do I take the current values of those text fields and add them to the database.
I have done it using the DetailedView which works at adding to the database but I also want to redirect to a different page after inserting.
So my question basically is how to take the values from the TextBox and insert them into the database, or how to I redirect to a different page after inserting a new row with DetailedView.
Here is my code with for the .aspx file, it has both the TextBox's and the detailed view
<p class=whiteMail>
First Name: <asp:TextBox ID="FirstName" runat="server"></asp:TextBox> <br />
Last Name: <asp:TextBox ID="LastName" runat="server"></asp:TextBox> <br />
E-Mail: <asp:TextBox ID="Email" runat="server"></asp:TextBox> <br />
Phone Number: <asp:TextBox ID="PhoneNumber" runat="server"></asp:TextBox> <br />
<asp:Button ID="Submit" runat="server" Text="Button" />
<br />
<asp:DetailsView ID="DetailsView2" runat="server" Height="50px" Width="125px"
DataSourceID="SqlDataSource1" AutoGenerateRows="False" CellPadding="4"
DataKeyNames="FirstName,PhoneNum,LastName" DefaultMode="Insert"
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="FirstName" HeaderText="First Name" ReadOnly="True"
SortExpression="FirstName" />
<asp:BoundField DataField="LastName" HeaderText="Last Name" ReadOnly="True"
SortExpression="LastName" />
<asp:BoundField DataField="PhoneNum" HeaderText="Phone Number" ReadOnly="True"
SortExpression="PhoneNum" />
<asp:BoundField DataField="Email" HeaderText="Email" SortExpression="Email" />
<asp:CommandField ShowCancelButton="False" ShowInsertButton="True" />
</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>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:Database1ConnectionString2 %>"
DeleteCommand="DELETE FROM [MailList] WHERE [FirstName] = #FirstName AND [PhoneNum] = #PhoneNum AND [LastName] = #LastName"
InsertCommand="INSERT INTO [MailList] ([FirstName], [PhoneNum], [Email], [LastName]) VALUES (#FirstName, #PhoneNum, #Email, #LastName)"
SelectCommand="SELECT [FirstName], [PhoneNum], [Email], [LastName] FROM [MailList]"
UpdateCommand="UPDATE [MailList] SET [Email] = #Email WHERE [FirstName] = #FirstName AND [PhoneNum] = #PhoneNum AND [LastName] = #LastName">
<DeleteParameters>
<asp:Parameter Name="FirstName" Type="String" />
<asp:Parameter Name="PhoneNum" Type="String" />
<asp:Parameter Name="LastName" Type="String" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="FirstName" Type="String" />
<asp:Parameter Name="PhoneNum" Type="String" />
<asp:Parameter Name="Email" Type="String" />
<asp:Parameter Name="LastName" Type="String" />
</InsertParameters>
<UpdateParameters>
<asp:Parameter Name="Email" Type="String" />
<asp:Parameter Name="FirstName" Type="String" />
<asp:Parameter Name="PhoneNum" Type="String" />
<asp:Parameter Name="LastName" Type="String" />
</UpdateParameters>
</asp:SqlDataSource>
<br />
</p>
And here is the .vb code
Public Class add
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
End Sub
Protected Sub Submit_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Submit.Click
Dim strURL As String = "message.aspx?firstname=" & FirstName.Text & "&lastname=" & LastName.Text()
Response.Redirect(strURL)
End Sub
Any help or suggestions would be great
I am not sure if I understood well, but I believe that your approach is not correct. Why you are using the textboxes in the beginning of the code?
You can achieve nicely what you want by using the full capability of the DetailsView. For example you can do something like this:
<asp:DetailsView ID="DetailsView2" runat="server" Height="50px" Width="125px"
DataSourceID="SqlDataSource1" AutoGenerateRows="False" CellPadding="4"
DataKeyNames="FirstName,PhoneNum,LastName" DefaultMode="Insert"
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:TemplateField HeaderText="FirstName" SortExpression="FirstName">
<ItemTemplate>
<asp:Label ID="Label1" runat="server"
Text='<%# Bind("FirstName") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server"
Text='<%# Bind("FirstName") %>'></asp:TextBox>
</EditItemTemplate>
<InsertItemTemplate>
<asp:TextBox ID="TextBox1" runat="server"
Text='<%# Bind("FirstName") %>'></asp:TextBox>
</InsertItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="LastName" SortExpression="LastName">
<ItemTemplate>
<asp:Label ID="Label2" runat="server"
Text='<%# Bind("LastName") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="TextBox2" runat="server"
Text='<%# Bind("LastName") %>'></asp:TextBox>
</EditItemTemplate>
<InsertItemTemplate>
<asp:TextBox ID="TextBox2" runat="server"
Text='<%# Bind("LastName") %>'></asp:TextBox>
</InsertItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="PhoneNum" SortExpression="PhoneNum">
<ItemTemplate>
<asp:Label ID="Label3" runat="server"
Text='<%# Bind("PhoneNum") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="TextBox3" runat="server"
Text='<%# Bind("PhoneNum") %>'></asp:TextBox>
</EditItemTemplate>
<InsertItemTemplate>
<asp:TextBox ID="TextBox3" runat="server"
Text='<%# Bind("PhoneNum") %>'></asp:TextBox>
</InsertItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Email" SortExpression="Email">
<ItemTemplate>
<asp:Label ID="Label4" runat="server"
Text='<%# Bind("Email") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="TextBox4" runat="server"
Text='<%# Bind("Email") %>'></asp:TextBox>
</EditItemTemplate>
<InsertItemTemplate>
<asp:TextBox ID="TextBox4" runat="server"
Text='<%# Bind("Email") %>'></asp:TextBox>
</InsertItemTemplate>
</asp:TemplateField>
<asp:CommandField ShowCancelButton="False" ShowEditButton="True" ShowInsertButton="True" />
</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>
And then in you code behind you can use the events of the DetailsView to do the redirect like this:
Protected Sub DetailsView1_ItemUpdated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DetailsViewUpdatedEventArgs) Handles DetailsView1.ItemUpdated
EndEditing()
End Sub
Protected Sub DetailsView1_ItemInserted(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DetailsViewInsertedEventArgs) Handles DetailsView1.ItemInserted
EndEditing()
End Sub
Private Sub EndEditing()
Response.Redirect("Default.aspx")
End Sub
I just used a the default.aspx for the redirect, but you can use any other page to redirect.
I hope that this can help you.

objectDataSource binding with ASP.NET gridview auto adding parameters

I have a gridview databound to an objectdatasource. Everything worked great until I changed 2 columns from asp:BoundField to asp:TemplateField. These are the UPC column and the Part column. I wanted to show a link button for each of these fields that take the user to another page. Now asp.net expects these two fields to be parameters on the update store procedure. Why is this? How do I get it to not assume these columns need to be passed to the store procedure?
Here is the code for the grid view:
<asp:GridView ID="GridView1" runat="server" SkinID="MSDefault" AutoGenerateColumns="False" DataSourceID="CartDataSource" PageSize="25"
Width="100%" DataKeyNames="CartId" EmptyDataText="The cart is empty" OnRowDataBound="GridView1_RowDataBound" onrowcommand="GridView1_RowCommand">
<Columns>
<asp:CommandField ShowDeleteButton="True" ShowEditButton="True">
<ItemStyle Width="8%" />
</asp:CommandField>
<asp:BoundField DataField="CartId" HeaderText="CartId" InsertVisible="False" ReadOnly="True"
SortExpression="CartId" Visible="False" />
<asp:TemplateField HeaderText="UPC" SortExpression="UPC">
<ItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server" CommandName="ShowInfo" CommandArgument='<%# Bind("UPC") %>' Text='<%# Bind("UPC") %>'></asp:LinkButton>
</ItemTemplate>
<ItemStyle Width="9%" />
</asp:TemplateField>
<asp:BoundField DataField="Mfr" HeaderText="Mfr" ReadOnly="True" SortExpression="Mfr">
<ItemStyle Width="11%" />
</asp:BoundField>
<asp:TemplateField HeaderText="Part" SortExpression="Part">
<ItemTemplate>
<asp:LinkButton ID="LinkButton2" runat="server" CommandName="ShowInfo" CommandArgument='<%# Bind("UPC") %>' Text='<%# Bind("Part") %>'></asp:LinkButton>
</ItemTemplate>
<ItemStyle Width="10%" />
</asp:TemplateField>
<asp:BoundField DataField="CustPart" HeaderText="Cust Part" ReadOnly="True" SortExpression="CustPart">
<ItemStyle Width="10%" />
</asp:BoundField>
<asp:BoundField DataField="PartDesc" HeaderText="Description" ReadOnly="True" SortExpression="PartDesc">
<ItemStyle Width="30%" Wrap="True" />
</asp:BoundField>
<asp:TemplateField HeaderText="Marked" SortExpression="Marked">
<EditItemTemplate>
<asp:CheckBox ID="CheckBox1" runat="server" Checked='<%# Bind("Marked") %>' />
</EditItemTemplate>
<ItemTemplate>
<asp:CheckBox ID="CheckBox1" runat="server" Checked='<%# Bind("Marked") %>' Enabled="false" />
</ItemTemplate>
<ItemStyle Width="2%" />
</asp:TemplateField>
<asp:BoundField DataField="Quantity" DataFormatString="{0:d}" HeaderText="Quantity"
SortExpression="Quantity">
<ItemStyle HorizontalAlign="Right" Width="4%" />
</asp:BoundField>
<asp:TemplateField HeaderText="Price" SortExpression="Price">
<ItemStyle HorizontalAlign="Right" Width="8%" />
<ItemTemplate>
<asp:Label ID="lblPrice" runat="server"></asp:Label>
<asp:LinkButton ID="LnkBtnCallLocalBranch" runat="server" Visible="false" PostBackUrl="~/UserProfile/LocalDistributors.aspx">call local branch</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Ext Price" SortExpression="ExtPrice">
<ItemStyle HorizontalAlign="Right" Width="8%" />
<ItemTemplate>
<asp:Label ID="lblExtPrice" runat="server"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
Here is the objectDataSource code
<asp:ObjectDataSource ID="CartDataSource" runat="server" OldValuesParameterFormatString="{0}" DeleteMethod="DeleteWithKey" SelectMethod="GetDataByCUserId"
TypeName="PunchoutData.CartDataSetTableAdapters.CartTableAdapter" UpdateMethod="UpdateQuantityAndMarked" OnUpdated="CartDataSource_Updated" OnObjectCreated="CartDataSource_ObjectCreated">
<DeleteParameters>
<asp:Parameter Name="cartid" Type="Int32" />
</DeleteParameters>
<UpdateParameters>
<asp:Parameter Name="marked" Type="Boolean" />
<asp:Parameter Name="quantity" Type="Int32" />
<asp:Parameter Name="cartid" Type="Int32" />
</UpdateParameters>
<SelectParameters>
<asp:SessionParameter Name="cuserid" SessionField="CUserId" Type="Int32" />
</SelectParameters>
</asp:ObjectDataSource>
Here is the error that is being generated
ObjectDataSource 'CartDataSource' could not find a non-generic method 'UpdateQuantityAndMarked' that has parameters: Marked, Quantity, CartId, UPC, Part.
The issue was that I was using <%# Bind("UPC") %> and I should have been using <%# Eval("UPC") %>. Bind is two-way and Eval is one-way(read-only)

Resources