2 Replies - 5427 Views - Last Post: 13 March 2008 - 01:05 AM Rate Topic: -----

#1 kkgaming  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 75
  • Joined: 07-February 07

How do I enable editing for grid view?

Posted 26 February 2008 - 03:11 PM

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

<%@ 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>
	<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" 
		<FooterStyle BackColor="#CCCC99" />
		<RowStyle BackColor="#F7F7DE" />
			<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" />
		<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: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]">

This post has been edited by kkgaming: 26 February 2008 - 03:45 PM

Is This A Good Question/Topic? 0
  • +

Replies To: How do I enable editing for grid view?

#2 Footsie  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 24
  • View blog
  • Posts: 370
  • Joined: 20-September 07

Re: How do I enable editing for grid view?

Posted 28 February 2008 - 01:42 AM

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.
Was This Post Helpful? 0
  • +
  • -

#3 vamsi kare  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 11-March 08

Re: How do I enable editing for grid view?

Posted 13 March 2008 - 01:05 AM


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.

		<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">
				<asp:Parameter Name="AccountCode" Type="String" />
				<asp:Parameter Name="AccountName" Type="String" />
				<asp:Parameter Name="AccountDescription" Type="String" />
				<asp:Parameter Name="AccountCode" Type="String" />
				<asp:Parameter Name="AccountCode" Type="String" />
				<asp:Parameter Name="AccountName" Type="String" />
				<asp:Parameter Name="AccountDescription" Type="String" />

This post has been edited by PsychoCoder: 13 March 2008 - 05:07 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1