Welcome to Dream.In.Code
Become an Expert!

Join 150,042 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,606 people online right now. Registration is fast and FREE... Join Now!




How do I enable editing for grid view?

 
Reply to this topicStart new topic

How do I enable editing for grid view?, Enable editing in grid view

kkgaming
26 Feb, 2008 - 02:11 PM
Post #1

D.I.C Head
**

Joined: 7 Feb, 2007
Posts: 75


My Contributions
(mod can move this to asp.net forum, my bad)
So all I am trying to do is enable editing for one of my GridView database so I can have "staff" update and edit the database when need be. In my gridview source I added AutoGenerateEditButton=True. However its telling me I need my data source to have an update command enabled. How do I go about this?? Any helps would be awesome.

CODE
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="edit.aspx.cs" Inherits="edit" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" [b]AutoGenerateEditButton="true"[/b]
        BackColor="White" BorderColor="#DEDFDE" BorderStyle="None" BorderWidth="1px"
        CellPadding="4" DataKeyNames="Guitar" DataSourceID="SqlDataSource1"
        ForeColor="Black" GridLines="Vertical"
        onselectedindexchanged="GridView1_SelectedIndexChanged">
        <FooterStyle BackColor="#CCCC99" />
        <RowStyle BackColor="#F7F7DE" />
        <Columns>
            <asp:BoundField DataField="Guitar" HeaderText="Guitar" ReadOnly="True"
                SortExpression="Guitar" />
            <asp:BoundField DataField="Color" HeaderText="Color" SortExpression="Color" />
            <asp:BoundField DataField="Type" HeaderText="Type" SortExpression="Type" />
            <asp:BoundField DataField="AMP" HeaderText="AMP" SortExpression="AMP" />
            <asp:BoundField DataField="Year" HeaderText="Year" SortExpression="Year" />
            <asp:BoundField DataField="Original_Price" HeaderText="Original_Price"
                SortExpression="Original_Price" />
            <asp:BoundField DataField="Sale_Price" HeaderText="Sale_Price"
                SortExpression="Sale_Price" />
        </Columns>
        <PagerStyle BackColor="#F7F7DE" ForeColor="Black" HorizontalAlign="Right" />
        <SelectedRowStyle BackColor="#CE5D5A" Font-Bold="True" ForeColor="White" />
        <HeaderStyle BackColor="#6B696B" Font-Bold="True" ForeColor="White" />
        <AlternatingRowStyle BackColor="White" />
    </asp:GridView>
    <div>
    
    </div>
    <asp:SqlDataSource ID="SqlDataSource1" runat="server"
        ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
        SelectCommand="SELECT [Guitar], [Color], [Type], [AMP], [Year], [Original Price] AS Original_Price, [Sale Price] AS Sale_Price FROM [Passwords]">
    </asp:SqlDataSource>
    </form>
</body>
</html>


This post has been edited by kkgaming: 26 Feb, 2008 - 02:45 PM
User is offlineProfile CardPM
+Quote Post

Footsie
RE: How Do I Enable Editing For Grid View?
28 Feb, 2008 - 12:42 AM
Post #2

D.I.C Regular
Group Icon

Joined: 20 Sep, 2007
Posts: 308



Thanked: 4 times
Dream Kudos: 50
My Contributions
It looks to me like you simply need to tell the database what action to take when someone edits your grid.

You only have a SelectCommand described here. So when the grid tries to Update a row (which is what will happen if you edit it) it cannot find the right command. Try adding an UpdateCommand under your select command.
User is offlineProfile CardPM
+Quote Post

vamsi kare
RE: How Do I Enable Editing For Grid View?
13 Mar, 2008 - 12:05 AM
Post #3

New D.I.C Head
*

Joined: 11 Mar, 2008
Posts: 4

Hi,

When you are configuring the SqlDatasouce for programming datagrid in asp.net, sql server, you click on the advanced button and set option in Advanced SQL generation options. Then the code will be generated as shown below.


CODE

<div>
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:FinAccountingConnectionString %>"
            DeleteCommand="DELETE FROM [AccountsTable] WHERE [AccountCode] = @AccountCode"
            InsertCommand="INSERT INTO [AccountsTable] ([AccountCode], [AccountName], [AccountDescription]) VALUES (@AccountCode, @AccountName, @AccountDescription)"
            SelectCommand="SELECT [AccountCode], [AccountName], [AccountDescription] FROM [AccountsTable]"
            UpdateCommand="UPDATE [AccountsTable] SET [AccountName] = @AccountName, [AccountDescription] = @AccountDescription WHERE [AccountCode] = @AccountCode">
            <DeleteParameters>
                <asp:Parameter Name="AccountCode" Type="String" />
            </DeleteParameters>
            <UpdateParameters>
                <asp:Parameter Name="AccountName" Type="String" />
                <asp:Parameter Name="AccountDescription" Type="String" />
                <asp:Parameter Name="AccountCode" Type="String" />
            </UpdateParameters>
            <InsertParameters>
                <asp:Parameter Name="AccountCode" Type="String" />
                <asp:Parameter Name="AccountName" Type="String" />
                <asp:Parameter Name="AccountDescription" Type="String" />
            </InsertParameters>
        </asp:SqlDataSource>


This post has been edited by PsychoCoder: 13 Mar, 2008 - 04:07 AM
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/8/09 09:54PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month