Hi,
I when I delete an item from the database through a Datagrid I want to get a messagebox poping
up to give me the choise to Confirm it...in case I clicked the wrong item....the way it works now it just deletes it....can any one help me with an Example I have no Idea how to do this...I found an article in C# but it didnt help me at all.here is my source code
<asp:DataGrid ID="dgCustList" Runat="server" AutoGenerateColumns="False" DataKeyField="id" AlternatingItemStyle-BackColor="#F6F6F6" HeaderStyle-BackColor="#C4B58E" CellSpacing="0" CellPadding="2" GridLines="Vertical" Width="100%" BorderWidth="0">
<Columns>
<asp:HyperLinkColumn DataTextField="Name" DataNavigateUrlField="id" DataNavigateUrlFormatString="cust_detail.aspx?id={0}" HeaderText="Rubrik" />
<asp:BoundColumn DataField="email" HeaderText="Email" ItemStyle-Width="160" ReadOnly="True" />
<asp:TemplateColumn HeaderText="Publiserad" ItemStyle-Width="80">
<ItemTemplate>
<%#Databinder.Eval(Container.DataItem, "posted", "{0:d}") %>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="edit_tbPosted" CssClass="time" Runat="server" Width="250" Text='<%# Databinder.Eval(Container.DataItem, "posted")%>' />
</EditItemTemplate>
</asp:TemplateColumn>
<asp:EditCommandColumn EditText="Ändra" CancelText="Avbryt" UpdateText="Spara" ItemStyle-HorizontalAlign="Right" />
<asp:ButtonColumn Text="Radera" ButtonType="LinkButton" CommandName="Delete" ItemStyle-HorizontalAlign="Right" />
</Columns>
</asp:DataGrid>
-Code Behind-
Sub dgCustList_Delete(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles dgCustList.DeleteCommandpnlNewCust.Visible = False
dgCustList.Visible = False
btnAddCust.Visible = FalseDim intCustId = dgCustList.DataKeys(Convert.ToInt32(e.Item.ItemIndex))
Dim Data As DataObjVB
Data = New DataObjVB()
dgCustList.DataSource = Data.DeleteCustomer(intCustId)
dgCustList.DataBind()lblMessage.Text = "the record has been deleted"
End Sub--------------
I hope Someone can help me cause im getting nuts here...I havent been programming enough for the last two years
Thanks
/Magnus
Magnus
![]() |
0 |
![]() |
Private Sub dgCustList_ItemCreated(ByVal sender As System.Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles dgCustList.ItemCreated Select Case e.Item.ItemType Case ListItemType.Item, ListItemType.AlternatingItem, ListItemType.EditItem Dim myTableCell As TableCellmyTableCell = e.Item.Cells(4) ' 4 indicates the column number which has delete button
Dim myDeleteButton As LinkButtonmyDeleteButton = myTableCell.Controls(0)
myDeleteButton.Attributes.Add("onclick", "return confirm('Are you sure you want to delete this ?');")
End Select End Sub
![]() |
0 |
![]() |
thanks I tried it but got this message
Specified argument was out of the range of valid values. Parameter name: index
I guess that ought to be related to the index of the Datakeyfield generated from in the Datagrid?
how do I fix that part..?thank you
/Magnus
Magnus
![]() |
0 |
![]() |
Hi,
Sorry for the late reply. I was on leave. The error is due to the index which you have specified is wrong. U have to change the index in,
myTabelcell=e.item.cells(4) ,
As i have mentioned earlier, cells(4) indicates the column number in which you have the delete link button. The indexes of the grid will start from zero. change the index and see it will really work.
kalyani
![]() |
0 |
![]() |