Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Datagrid insert problem

Status
Not open for further replies.

RandyBlackburn

Programmer
Oct 1, 2002
153
US
I'm using the datagrid insert technique where a default record is inserted, then updated.

What I have found is that it is possible for a user to edit or delete another lineitem before updating or cancelling the insert.

How would I best solve this problem?

I guess I can hide the delete column, but how would I disable the edit link buttons on all the other records (including other pages)?

Also, I could give a javascript alert if they try to click on either an "edit" or "delete" link, but I'm not sure how to do that. I currently have the following logic already associated with the delete link button:

Private Sub CreditorGrid_ItemCreated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles CreditorGrid.ItemCreated
Select Case e.Item.ItemType
Case ListItemType.Item, ListItemType.AlternatingItem, ListItemType.EditItem
Dim myTableCell As TableCell
myTableCell = e.Item.Cells(13)
Dim myDeleteButton As LinkButton
myDeleteButton = myTableCell.Controls(0)
myDeleteButton.Attributes.Add("onclick", _
"return confirm('Are you Sure you want to delete this Creditor?');")
End Select

Thanks in advance,
Randy
 
Randy:
What I have found is that it is possible for a user to edit or delete another lineitem before updating or cancelling the insert.
This is not, to me at least, entirely clear exactly what it is you are trying to attempt; and why it is different from a standard editing approach (not to be critical). Give a brief 3 or 4 step approach in bulleted format exactly what you are trying to accomplish. Whatever it is, its doable --
 
I know this to be a problem I have as well. I just take the approach as a training issue. Mainly because I haven't had time to really correct this.

But, what you probally could do is use the itemdatabound event of the grid and do something like

If e.Item.ItemType = ListItemType.EditItem Then

disable or hide the footer of the grid. I assume you insert your records using the footer correct? The itemdatabound would probably be your best bet with something like this.

hope this helps

 
Actually, I'm adding thenew record at the top via this code, attached to an add button:

Me.DsCreditor1.LeadCreditor().Rows.InsertAt(dr, 0)

Session("DsCreditor1") = DsCreditor1
CreditorGrid.EditItemIndex = 0
CreditorGrid.DataBind()
 
I'm not sure what you mean by at the top? either it's the footer or in edit mode. if your in edit mode I would switch to using the footer. That is the correct way to insert records from a grid.

 
It is inserting at row 0. Which was recommended by msdn or some other source. I actually prefer adding data at the top of the grid.

But the problem is the same, I think. If you enter data into the footer, aren't you still inserting first, then updating?

The original problem was that if the insert has completed, but not the update, and the user clicks on edit or delete in another line item, then the insert is left hanging, and may not be complete.

I've actually solved this by testing to see whether the add button is visible or not in the on-edit routine. If not visible, it means the update portion has not been completed. I then emit a js alert telling them to update or cancel the new record, and exit the onedit.

To eliminate deletes, I hide the delete column until the insert/update is complete.

What I haven't figured out, is how to somehow deactivate the edit and delete link buttons, if I wanted to approach the problem that way.
 
If you enter data into the footer, aren't you still inserting first, then updating?

NO..if your add button is located in the footer that's all your doing is inserting period. use your edititem section to Edit, Update, Cancel or Delete your records.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top