473,795 Members | 2,452 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Help with ASP.NET Datagrid

I'm having trouble with the UpdateCommand event with the
DataGrid control. The event is wired up in the
InitializeCompo nents properly,

this.sitesDataG rid.UpdateComma nd +=
new System.Web.UI.W ebControls.Data GridCommandEven tHandler
(this.sitesData Grid_UpdateComm and);

but when the "Update" button is clicked, the eventhandler
is never fired. The "Edit" command fires its
eventhandler, but "Update" and "Cancel" do not.

One peculiar thing I have noticed is that the ItemCommand
event fires for both the Edit and Update button. However,
for both, the CommandName (e.CommandName) is always "Edit".

What am I doing wrong???

Thanks in advance!!
Nov 15 '05 #1
3 1917
Hi Fortra,

Here is the code I'm using for this.

I''m using asp:TemplateCol umn to define my columns.

This is how I declare the grid in the ASP.NET page:
<asp:datagrid id=recordgrid runat="server" ShowHeader="fal se"
OnPageIndexChan ged="Grid_Chang e" PagerStyle-Visible="False"
GridLines=Horiz ontal BorderStyle="no ne" BackColor="whit e"
autoGenerateCol umns="False" DataSource="<%# GetDataGridSour ce()%>"
showfooter="Fal se" visible="true" OnEditCommand=" RecordEditComma nd"
OnDeleteCommand ="RecordDeleteC ommand" Width="100%" CellPadding="0" >

As you can see I declare the OnEditCommand, OnDelete directly in the page,
this avoid using InitializeCompo nents for this and is a cleaner solution
IMO.

The "Action" column is declared as:

<asp:templateco lumn ItemStyle-VerticalAlign=" Top" ItemStyle-Width="25"
ItemStyle-HorizontalAlign ="Center" >
<itemtemplate >
<asp:imagebutto n ToolTip="Edit Record" runat="server"
Visible="true" CommandName="Ed it" ImageUrl="image s/ico_edit.gif"
ID="Imagebutton 2" />
</itemtemplate>
</asp:templatecol umn>

As you see I'm using the CommandName property of the button, this indicate
what is the event to be risen on the datagrid.

As I said this come from a working page so you should have no problem using
it.

Hope this help,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Fortra" <an*******@disc ussions.microso ft.com> wrote in message
news:04******** *************** *****@phx.gbl.. .
I'm having trouble with the UpdateCommand event with the
DataGrid control. The event is wired up in the
InitializeCompo nents properly,

this.sitesDataG rid.UpdateComma nd +=
new System.Web.UI.W ebControls.Data GridCommandEven tHandler
(this.sitesData Grid_UpdateComm and);

but when the "Update" button is clicked, the eventhandler
is never fired. The "Edit" command fires its
eventhandler, but "Update" and "Cancel" do not.

One peculiar thing I have noticed is that the ItemCommand
event fires for both the Edit and Update button. However,
for both, the CommandName (e.CommandName) is always "Edit".

What am I doing wrong???

Thanks in advance!!

Nov 15 '05 #2
Thanks again!

I did find my problem in the code-behind class - in the
InitializeCompo nents() method, I was calling the datagrid's
DataBind() method, event though I defined a BindData()
method to handle this that was called in the Page_Load()
method based on the IsPostBack property. As soon as I
removed this extra call, all of my datagrid events wired
up properly.

-----Original Message-----
Hi Fortra,

Here is the code I'm using for this.

I''m using asp:TemplateCol umn to define my columns.

This is how I declare the grid in the ASP.NET page:
<asp:datagri d id=recordgrid runat="server" ShowHeader="fal se"OnPageIndexCha nged="Grid_Chan ge" PagerStyle- Visible="False" GridLines=Horiz ontal BorderStyle="no ne" BackColor="whit e"autoGenerateCo lumns="False" DataSource="<%# GetDataGridSour ce()%>" showfooter="Fal se" visible="true" OnEditCommand=" RecordEditComma nd" OnDeleteCommand ="RecordDeleteC ommand" Width="100%" CellPadding="0" >
As you can see I declare the OnEditCommand, OnDelete directly in the page,this avoid using InitializeCompo nents for this and is a cleaner solutionIMO.

The "Action" column is declared as:

<asp:templatec olumn ItemStyle-VerticalAlign=" Top" ItemStyle-Width="25"ItemStyle-HorizontalAlign ="Center" >
<itemtemplate >
<asp:imagebutto n ToolTip="Edit Record" runat="server"Visible="tru e" CommandName="Ed it" ImageUrl="image s/ico_edit.gif"ID="Imagebutto n2" />
</itemtemplate>
</asp:templatecol umn>

As you see I'm using the CommandName property of the button, this indicatewhat is the event to be risen on the datagrid.

As I said this come from a working page so you should have no problem usingit.

Hope this help,

--
Ignacio Machin,
ignacio.mach in AT dot.state.fl.us
Florida Department Of Transportation

"Fortra" <an*******@disc ussions.microso ft.com> wrote in messagenews:04******* *************** ******@phx.gbl. ..
I'm having trouble with the UpdateCommand event with the
DataGrid control. The event is wired up in the
InitializeCompo nents properly,

this.sitesDataG rid.UpdateComma nd +=
new System.Web.UI.W ebControls.Data GridCommandEven tHandler (this.sitesData Grid_UpdateComm and);

but when the "Update" button is clicked, the eventhandler is never fired. The "Edit" command fires its
eventhandler, but "Update" and "Cancel" do not.

One peculiar thing I have noticed is that the ItemCommand event fires for both the Edit and Update button. However, for both, the CommandName (e.CommandName) is always "Edit".
What am I doing wrong???

Thanks in advance!!

.

Nov 15 '05 #3
Hi,

Yes, of course I use it, it's there where the RecordEditComma nd method is
declared , what I declare in the aspx code is which method in the code
behind will handle the event. I think this easier that use hook the event in
the InitializeCompo nents method.

Hope this help,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Fortra" <an*******@disc ussions.microso ft.com> wrote in message
news:01******** *************** *****@phx.gbl.. .
So you do not use a code-behind file for the UpdateCommand
event handler? You embed it directly on the page?
-----Original Message-----
Hi Fortra,

Here is the code I'm using for this.

I''m using asp:TemplateCol umn to define my columns.

This is how I declare the grid in the ASP.NET page:
<asp:datagri d id=recordgrid runat="server"

ShowHeader="fal se"
OnPageIndexCha nged="Grid_Chan ge" PagerStyle-

Visible="False"
GridLines=Horiz ontal BorderStyle="no ne"

BackColor="whit e"
autoGenerateCo lumns="False" DataSource="<%#

GetDataGridSour ce()%>"
showfooter="Fal se" visible="true"

OnEditCommand=" RecordEditComma nd"
OnDeleteCommand ="RecordDeleteC ommand"

Width="100%" CellPadding="0" >

As you can see I declare the OnEditCommand, OnDelete

directly in the page,
this avoid using InitializeCompo nents for this and is a

cleaner solution
IMO.

The "Action" column is declared as:

<asp:templatec olumn ItemStyle-VerticalAlign=" Top"

ItemStyle-Width="25"
ItemStyle-HorizontalAlign ="Center" >
<itemtemplate >
<asp:imagebutto n ToolTip="Edit Record"

runat="server"
Visible="tru e" CommandName="Ed it"

ImageUrl="image s/ico_edit.gif"
ID="Imagebutto n2" />
</itemtemplate>
</asp:templatecol umn>

As you see I'm using the CommandName property of the

button, this indicate
what is the event to be risen on the datagrid.

As I said this come from a working page so you should

have no problem using
it.

Hope this help,

--
Ignacio Machin,
ignacio.mach in AT dot.state.fl.us
Florida Department Of Transportation

"Fortra" <an*******@disc ussions.microso ft.com> wrote in

message
news:04******* *************** ******@phx.gbl. ..
I'm having trouble with the UpdateCommand event with the
DataGrid control. The event is wired up in the
InitializeCompo nents properly,

this.sitesDataG rid.UpdateComma nd +=
new System.Web.UI.W ebControls.Data GridCommandEven tHandler (this.sitesData Grid_UpdateComm and);

but when the "Update" button is clicked, the eventhandler is never fired. The "Edit" command fires its
eventhandler, but "Update" and "Cancel" do not.

One peculiar thing I have noticed is that the ItemCommand event fires for both the Edit and Update button. However, for both, the CommandName (e.CommandName) is always "Edit".
What am I doing wrong???

Thanks in advance!!

.

Nov 15 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
2447
by: Bruce Pullum | last post by:
I have a datagrid that I am using a DataView with. All works great for the sorting of the columns. However, after I sort the column, and then try and select a data row to edit, the row selected represents the indes of the actual DataGrid and not the DataView. For example.. Lets say I have 4 rows of data.. In the 4 rows I have an Appt Num of 1,2,3,4... Each representing a data row... I sort DESC so the rows display 4,3,2,1... If I...
2
5143
by: Anita C | last post by:
Hi, How do I associate or map a specific column in a datatable to a particular element present in an xml document - to read into a datatable as well as write from the datatable to the xml element? Also, how can I associate all the attributes and their values of a particular element to the Name & Value columns of a datatable - to read into a datatable as well as write from the datatable to the xml element? Any help will be greatly...
8
3131
by: pei_world | last post by:
Hi, there; I have a problem with my datagrid control. I declared it in one of my form, set with DataGridTalbeStyle as well, and when I click on button, I would like to retrive Data from Database and bind these data to my datagrid in the form, when I click the button first time, it work fine. but when I click the second button. it report belowing error, I guess it is because it already set up the column name at first time, so cann't do...
0
3646
by: Patrick | last post by:
I'm working on a contact management application, and need a hand with one aspect... Here's what I want to create: ------------------------------------ A form split into two parts. There is a datagrid on the left side that lists names and perhaps a couple of other key fields. The user can click on a record in the datagrid, which should automatically pull up details on that record in the various text boxes and other controls on the right...
1
1517
by: Michael Gorbach | last post by:
Iv got a StatisticsContainer object that contains an arraylist of objects of different types, all inherited from class Statistic. The statistics class has 2 string public properties, name and stringValue. The classes that inherit from it use those two properties, plus several properties of their own of types double and vector. I need to display this StatisticsContainer class on a datagrid, but I'm having problems because each of the...
14
1844
by: Brett Sinclair | last post by:
Hello everybody I'm still on the learning curve here...and from what I read, I created inherited datagrid class so I could have icons, combobox...etc in the columns of my datagrid. The grid will be used to populate information coming from a Webservice. (No datasets - No datareaders). So, I do not know see how to use the "datasource".
6
4688
by: Coleen | last post by:
Hi All :-) Thanks for all of your help Cor :-) I can not get the code you sent me to work in my application. I'm using an aspx datagrid in a web form. I'm getting the following error message when I try this code: "Syntax error in aggregate argument: Expecting a single column argument with possible 'Child' qualifier." Dim dr2 As DataRow = dt_stat_report_3b.NewRow Dim sum As Double =...
2
1323
by: Brad Shook | last post by:
First of all thinks to Cor Ligthert for helping me with this last week. If you wild like to read Cor's comments please refer to the posting from 10/14/2004 and 8:48AM "Help with Advanced Datagrid" I am trying to bind one column of a datagrid to a seperate textbox and the rest of the fields to a datagrid. the comments are too large to fit in a datagrid so I created a textbox below the datagrid and need it to hold the data for the...
3
2521
by: Datatable Dataset Datagrid help | last post by:
Hi I am somewhat confused, I am new at VB.net I use XML data, I have a datagrid, I created a datatable so that I can create a custom format like true is this graphic false is this graphic and others. One of the custom format is as follows: dsmessages_dt.Columns.Add("Image", GetType(Image)) I had a problem of when I used a checkbox in the grid that was bound to the datatable that it would not update my dataset. So I created another...
4
2138
by: Jeff User | last post by:
Hi I tryed to solve this problem over in the framework.asp group, but still am having trouble. Hope someone here can help. using .net 1.1, VS 2003 and C# I have an asp.DataGrid control with a Delete button on the end of each row. I am unable to gain access to the event when the button is clicked. I don't fully understand how the click gets connected to the C# code,
0
9672
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10437
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10214
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10164
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10001
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7538
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5563
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3723
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2920
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.