Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

web app - Datagrid - adding an edit function to each row using buttons in a new column

Posted on 2004-11-03
9
Medium Priority
?
140 Views
Last Modified: 2011-10-03
Could someone please lead me on a step by step way of:

1) making a new column at the front of the grid
2) sticking a button with text "Edit" in that column so that it appears by each row
3) accessing an edit-button-clicked event in code?

I have 1 and 2 working right (I think) but in case I did something wrong, please be thorough.

JP
0
Comment
Question by:gleznov
  • 5
  • 4
9 Comments
 
LVL 18

Accepted Solution

by:
tusharashah earned 2000 total points
ID: 12486446
1) making a new column at the front of the grid
--> Right Click DataGrid --> Property Builder --> Columns --> Add "Bound Column" to Selected Columns on right hand side --> DataField Property will represent Column name from DataBase

2) sticking a button with text "Edit" in that column so that it appears by each row
--> Right Click DataGrid --> Property Builder --> Columns --> Expand Button Column --> Add "Edit, Update, Cancle" Column to Selected Columns on right hand side, Click OK!

[If you want to open a new page for editing then you can add "SELECT" Column and Modify Text Property of that colum to Edit]

3) accessing an edit-button-clicked event in code?
--> Go  to Code Behind --> Select and add this events fro DataGrid: 'DataGrid1_EditCommand', 'DataGrid1_CancelCommand', 'DataGrid1_UpdateCommand'

Add following code for Edit & Cancel event:
    Sub DataGrid1_EditCommand(sender As Object, e As DataGridCommandEventArgs)
        MyDataGrid.EditItemIndex = e.Item.ItemIndex
        BindGrid
    End Sub

    Sub DataGrid1_CancelCommand(sender As Object, e As DataGridCommandEventArgs)
        MyDataGrid.EditItemIndex = -1
        BindGrid
    End Sub

& Check out following link for what you can write in Update & to see whole process..
http://samples.gotdotnet.com/quickstart/util/srcview.aspx?path=/quickstart/aspplus/samples/webforms/ctrlref/webctrl/datagrid/datagrid6.src

Working Sample:
http://samples.gotdotnet.com/quickstart/aspplus/samples/webforms/ctrlref/webctrl/datagrid/VB/datagrid6.aspx

-tushar
0
 

Author Comment

by:gleznov
ID: 12486690
One more question - I'd like to have the button reference the row and trigger some code, such that I fill in text/combo boxes with that row's info and let them edit outside the grid rather than in the grid.  Is that easy?  Or am I better off sticking to grid editing?

JP
0
 
LVL 18

Expert Comment

by:tusharashah
ID: 12486796
Even I found Editing outside more comfortable..

You can do that in two ways:

1) Adding HyperLink Column and passing ID of specific record to next page as QueryString.
Example: http://samples.gotdotnet.com/quickstart/aspplus/samples/webforms/ctrlref/webctrl/datagrid/VB/datagrid3.aspx
Code: http://samples.gotdotnet.com/quickstart/util/srcview.aspx?path=/quickstart/aspplus/samples/webforms/ctrlref/webctrl/datagrid/datagrid3.src

2) Store Data On Session or retrive them using the method shown here:
Example: http://samples.gotdotnet.com/quickstart/aspplus/samples/webforms/ctrlref/webctrl/datagrid/VB/datagrid4.aspx
Code: http://samples.gotdotnet.com/quickstart/util/srcview.aspx?path=/quickstart/aspplus/samples/webforms/ctrlref/webctrl/datagrid/datagrid4.src
[Sub Grid_CartCommand is the command that you need to implement]

-tushar
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.

 

Author Comment

by:gleznov
ID: 12496851
The example under 1) in your last post, tush, is mainly what I'm looking for.  But I don't understand how to cross apply that information to using the VB.NET GUI and .aspx.vb code behind.  

JP
0
 
LVL 18

Expert Comment

by:tusharashah
ID: 12496987
If you're using Visual Studio in the codebehind (.vb file) you'll see 2 drop down menu on top with different events for page. You can select different events from that menu.

Now, whenever you Build your project YourApplication.dll will be created automatically in your <bin> directory. And that will bind your code with ASPX file. ( i believe this is what you want to know)

-tushar
0
 

Author Comment

by:gleznov
ID: 12497031
OK actually I got that working using a "Select" button in the property builder.  Now I have an even ickier problem.  My datagrid has paging.  5 items per page.  When I page over and click the button next to the first item, it's referencing item 0 instead of item 5 on the next page.  

JP
0
 
LVL 18

Expert Comment

by:tusharashah
ID: 12497069
Dear JP, that would be a completely different question from original.. You should close this QUestion and open a new one for that.

-tushar
0
 

Author Comment

by:gleznov
ID: 12497088
Thanks Tush!
0
 
LVL 18

Expert Comment

by:tusharashah
ID: 12497107
Thanks for understanding.. i'll be on your paging question soon...

-tushar
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Integration Management Part 2
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses
Course of the Month20 days, 17 hours left to enroll

810 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