Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

how to add edit column in datagrid?

Posted on 2004-09-13
7
Medium Priority
?
396 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 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.

 
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

636 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