?
Solved

how to add edit column in datagrid?

Posted on 2004-09-13
7
Medium Priority
?
398 Views
Last Modified: 2008-01-09
actually I have add the Edit buttonlink in the datagrid using the datagrid properties diaolog box ..
so, what are the next steps? so that I could use the Edit link to edit the entire row of data..
thank you.
0
Comment
Question by:p931226
  • 3
  • 3
7 Comments
 
LVL 28

Accepted Solution

by:
mmarinov earned 200 total points
ID: 12042903
Hi,

you have to create an edit command event like this

vb
      Sub ItemsGrid_Edit(sender As Object, e As DataGridCommandEventArgs)

         ' Set the EditItemIndex property to the index of the item clicked
         ' in the DataGrid control to enable editing for that item. Be sure
         ' to rebind the DateGrid to the data source to refresh the control.
         ItemsGrid.EditItemIndex = e.Item.ItemIndex
         BindGrid()

      End Sub
      Sub BindGrid()

         ' Set the data source and bind to the Data Grid control.
         ItemsGrid.DataSource = CartView
         ItemsGrid.DataBind()

      End Sub


c#
      void ItemsGrid_Edit(Object sender, DataGridCommandEventArgs e)
      {

         // Set the EditItemIndex property to the index of the item clicked
         // in the DataGrid control to enable editing for that item. Be sure
         // to rebind the DateGrid to the data source to refresh the control.
         ItemsGrid.EditItemIndex = e.Item.ItemIndex;
         BindGrid();

      }
      void BindGrid()
      {

         // Set the data source and bind to the Data Grid control.
         ItemsGrid.DataSource = CartView;
         ItemsGrid.DataBind();

      }

and in your html tag asp:datagrid you have to add
OnEditCommand="ItemsGrid_Edit"


Regards,
B..M
0
 

Author Comment

by:p931226
ID: 12050267
Hi mmarinov,

I have used ur code given..
but stil can't edit the entire row?
when I click on the Edit link, it has no reaction??
Why can't it change to a row that is editable?
TQ
0
 

Author Comment

by:p931226
ID: 12050307
when I put OnEditCommand="myGrid_Edit" inside the html tag asp:datagrid
It has this error:
-----------------------------------------------------------------------------------
Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: CS0122: 'Las.UserControl.myGrid_Edit(object, System.Web.UI.WebControls.DataGridCommandEventArgs)' is inaccessible due to its protection level
--------------------------------------------------------------------------------------------
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 2

Assisted Solution

by:mangesh004
mangesh004 earned 80 total points
ID: 12051977
Hi friend,

If you are using VB.NET and VB code behind files to write your code, then follow these steps

1. open that file (for example sample.aspx.vb)
2.you can see two dropdown lists at the top
3. from first choose your data grid name (known as class name)
4.from the second dropdownlist choose method name called as EditCommand
5. when you do this you can see that a new procedure  is created , as follows

Private Sub DataGrid1_EditCommand(ByVal source As Object, ByVal e As
System.Web.UI.WebControls.DataGridCommandEventArgs) Handles DataGrid1.EditCommand
   
End Sub

6.write the following code into it

DataGrid1.EditItemIndex = e.Item.ItemIndex
fill_datagrid()  ‘ your procedure which binds the grid with Data

7.things to be taken care of
   
a) if you are populating the grid in the page load event itself put that code into if loop as
If IsPostBack = False Then
            fill_datagrid()
End If

b)see to it that you have not set the properties of the column to Read only
-------- It should definetly work

Thanking you
Mangesh
0
 
LVL 28

Expert Comment

by:mmarinov
ID: 12052713
you have to crea the event of your datagrid:
1. first way is by clicking on the datargid control in the design mode , select the events and double click on the ItemEdit command
2. the second way is to put public before your event definition so the asp.net process to know which sub have to execute when the edit command event is rised

if you don't have on of these scenarious you will not be switched to the edit mode of the selected row

B..M
0
 

Author Comment

by:p931226
ID: 12053888
I'm using C#

Whenever I removed the OnEditCommand="myGrid_Edit" from the html tag..
it has no error..
but when I click on Edit link..
it will change to Update and Cancel..
what to put inside the

            void myGrid_Cancel(Object sender, DataGridCommandEventArgs e)
            {


                  myGrid.EditItemIndex = -1;
                  BindGrid();
                  
            }
 
            void myGrid_Update(Object sender, DataGridCommandEventArgs e)
            {
                  
            
            }
 
=====================
I have put some codes in the myGrid_Cancel function..
but seems like no respond...
is it bcos of I din't put the
OnCancelCommand in the html tag?

0
 
LVL 28

Expert Comment

by:mmarinov
ID: 12054177
the code in onCancelCommand event seems to be ok - it should return in preview mode,
in the update mode you have to get the values of the editable boxes and update them in the database

to see a full example see here :
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemwebuiwebcontrolsdatagridclasseditcommandtopic.asp

B..M
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question