problem with Datagrid - Asp.net 2.0

Posted by Gayathri under ASP.NET on 4/2/2010 | Views : 1540 | Status : [Member] | Replies : 2
Below mentioned is a simple aspx page with a datagrid specified columns.

i am confused why i am not getting OnEditCommand, OnUpdateCommand in dAtagrid <asp:GridView>
Also please let me know the significance of Alternating template field ,Edit template, Header template, footer and Item Template.

Thanks in ADvance
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!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">
<div>
<asp:GridView ID="GridView1" runat="server"
AutoGenerateColumns="False" DataSourceID="sqlrec" Font-Names="Verdana"
Font-Size="XX-Small" >
<Columns>
<asp:BoundField DataField="name" HeaderText="name" />
<asp:BoundField DataField="f_name" HeaderText="f_name" />
<asp:BoundField DataField="l_name" HeaderText="l_name" />
<asp:BoundField DataField="city" HeaderText="city" />
<asp:BoundField DataField="state" HeaderText="state" />
<asp:BoundField DataField="id" HeaderText="id" />
<asp:ButtonField ButtonType="Button" Text="Add" />
<asp:ButtonField ButtonType="Button" Text="Save" />
<asp:ButtonField ButtonType="Button" Text="Update" />

</Columns>
</asp:GridView>
<asp:SqlDataSource ID="sqlrec" runat="server" ConnectionString="<%$ ConnectionStrings:modelConnectionString %>"
SelectCommand="SELECT * FROM [record]"></asp:SqlDataSource>

</div>
</form>
</body>
</html>




Responses

Posted by: Vuyiswamb on: 4/2/2010 [Member] [MVP] [Administrator] NotApplicable

Up
0
Down
You need to enable these properties first

AutoGenerateDeleteButton="True"

AutoGenerateEditButton="True"
AutoGenerateSelectButton="True"


that means you need to change your grid to this

<asp:GridView ID="GridView1" runat="server" 

AutoGenerateColumns="False" AutoGenerateDeleteButton="True" AutoGenerateEditButton="True"
AutoGenerateSelectButton="True" DataSourceID="sqlrec" Font-Names="Verdana"
Font-Size="XX-Small" >
<Columns>
<asp:BoundField DataField="name" HeaderText="name" />
<asp:BoundField DataField="f_name" HeaderText="f_name" />
<asp:BoundField DataField="l_name" HeaderText="l_name" />
<asp:BoundField DataField="city" HeaderText="city" />
<asp:BoundField DataField="state" HeaderText="state" />
<asp:BoundField DataField="id" HeaderText="id" />
<asp:ButtonField ButtonType="Button" Text="Add" />
<asp:ButtonField ButtonType="Button" Text="Save" />
<asp:ButtonField ButtonType="Button" Text="Update" />

</Columns>
</asp:GridView>


and right click on your grid and get Visual Studio to generate the events for you. i see you expcted the
OnUpdateCommand event , well in ASP.NET they are named as

RowEditing

RowUpdated
and ect.

Thank you for posting at DotnetFunda

Vuyiswa Maseko

Thank you for posting at Dotnetfunda
[Administrator]

Gayathri, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Syedshakeer on: 4/2/2010 [Member] Starter

Up
0
Down
Hi,
check the following link
http://www.dotnetspark.com/kb/643-how-to-editupdatedelete-gridview.aspx

Syed Shakeer Hussain

Gayathri, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response