datagrids + buttons

mike55

Contributor
Joined
Mar 26, 2004
Messages
727
Location
Ireland
Hi

Have a datagrid that is bounded to my employees table in SQL Server, have a select and a delete button in the datagrid, so that when you press the select button, the program will take the employeeid of the selected row, go to the database and pull back all the data, with the delete button it simple gets the employeeId and deletes the entry from the table.

After creating my datagrid, i went into the Html code and added onDeleteCommand = "Grid_delete", then in the vb.net code i have created a method "Grid_delete" which takes an object (sender) and a DataGridCommandEventArg (e), the problem is what do i do next, i have a book example for the edit link button, however i was unable to get the code working. Would appreciate any assistance or any links.

Mike55
 
Ok,

Am after doing some searching,and i figured out how to get the employeeid using: e.item.cells(ColumnNumber).text). Now this code gets the column number no problem however when i try to pass on this number, i does n't seem to work, an i suppose to have added anything else to the code from the datagrid.

Mike55 :-\
 
If I understand your question correctly, the datagrid exposes a DataKeys property, where you can set the name of your primary key column. When you catch the datagrid's edit event, you can pull the key right off the 'e' arguments, CommandArgument property.

HTH
 
I have no problem getting the value i need, the problem is in the passing the value i retrieved onto the next destination, there is no problem if i hardcode in the value.

Mike55
 
mike55 said:
I have no problem getting the value i need, the problem is in the passing the value i retrieved onto the next destination, there is no problem if i hardcode in the value.

Mike55
I think it would help if you would post a small code snippet so we can see where you are having troubles.
 
TwistedNerve said:
I think it would help if you would post a small code snippet so we can see where you are having troubles.

In the Html code i have added the following section in the datagrid tags:
on deleteCommand = "Grid_delete"

In the vb.net code i have added the following method:
sub Grid_delete(byVal sender as object, byval e as datagridcommandeventargs) Handles dgEmployee.deletecommand
Dim y as string
y = e.item.cells(1).text
x.deleteEmployee(y) 'Delete employee.
employee() 'Reloads the datagrid.
end sub

The problem occures in the ling x.deleteEmployee(y) in that when y is passed on to the next destination, it looses its value.

Mike55
 
Yea, have stepped through the code line by line, have seen y pick up the value but loose it when it passes the value onto the next destination.

Mike55
 
Back
Top