Solved

how to add edit column in datagrid?

Posted on 2004-09-13
7
381 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 50 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
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 2

Assisted Solution

by:mangesh004
mangesh004 earned 20 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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

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…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

747 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now