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

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
gleznovAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

tusharashahCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
gleznovAuthor Commented:
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
tusharashahCommented:
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
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

gleznovAuthor Commented:
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
tusharashahCommented:
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
gleznovAuthor Commented:
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
tusharashahCommented:
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
gleznovAuthor Commented:
Thanks Tush!
0
tusharashahCommented:
Thanks for understanding.. i'll be on your paging question soon...

-tushar
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.