iflash
asked on
Adding "Delete Confirmation" in DetailsView for .NET 2.0
Could anyone tell me how to put delete confirmation pop up in detailsview control? (in VB.NET)
I created 3 button ( Edit, Delete, New) as commandfield. I tried with <asp:templatefield> and it works but I would like implement in <asp:commandfield>.
Thanks in advance.
<asp:CommandField ButtonType="Button" ShowDeleteButton="True" ShowEditButton="True" ShowInsertButton="True" />
'I would like to implement on above line.
<%-- <asp:TemplateField>
<ItemTemplate>
<asp:LinkButton
Text="Delete" runat="server" Commandname="delete" OnClientClick="return confirm('Delete?');">
</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>--%>
I created 3 button ( Edit, Delete, New) as commandfield. I tried with <asp:templatefield> and it works but I would like implement in <asp:commandfield>.
Thanks in advance.
<asp:CommandField ButtonType="Button" ShowDeleteButton="True" ShowEditButton="True" ShowInsertButton="True" />
'I would like to implement on above line.
<%-- <asp:TemplateField>
<ItemTemplate>
<asp:LinkButton
Text="Delete" runat="server" Commandname="delete" OnClientClick="return confirm('Delete?');">
</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>--%>
ASKER
Ahh.. the code you gave doesnt seem to work for DetailsView... or maybe I'm just not experienced enough :(
After surfing for hours I've found a solution in C#... however I need it in VB because my C skills are non-existent. Do you know the VB equivalent for:
-------------------------- ---------- ---------- ---------- ---------- ---------- ---------- ------
protected void DetailsView1_ItemCreated(o bject sender, EventArgs e)
{
// Test FooterRow to make sure all rows have been created
if (DetailsView1.FooterRow != null)
{
// The command bar is the last element in the Rows collection
int commandRowIndex = DetailsView1.Rows.Count-1;
DetailsViewRow commandRow = DetailsView1.Rows[commandR owIndex];
// Look for the DELETE button
DataControlFieldCell cell = (DataControlFieldCell) commandRow.Controls[0];
foreach(Control ctl in cell.Controls)
{
LinkButton link = ctl as LinkButton;
if (link != null)
{
if (link.CommandName == "Delete")
{
link.ToolTip = "Click here to delete";
link.OnClientClick = "return confirm('Do you really want to delete this record?');";
}
}
}
}
-------------------------- ---------- ---------- ---------- ---------- ---------- ---------- ------
That would help heaps!
After surfing for hours I've found a solution in C#... however I need it in VB because my C skills are non-existent. Do you know the VB equivalent for:
--------------------------
protected void DetailsView1_ItemCreated(o
{
// Test FooterRow to make sure all rows have been created
if (DetailsView1.FooterRow != null)
{
// The command bar is the last element in the Rows collection
int commandRowIndex = DetailsView1.Rows.Count-1;
DetailsViewRow commandRow = DetailsView1.Rows[commandR
// Look for the DELETE button
DataControlFieldCell cell = (DataControlFieldCell) commandRow.Controls[0];
foreach(Control ctl in cell.Controls)
{
LinkButton link = ctl as LinkButton;
if (link != null)
{
if (link.CommandName == "Delete")
{
link.ToolTip = "Click here to delete";
link.OnClientClick = "return confirm('Do you really want to delete this record?');";
}
}
}
}
--------------------------
That would help heaps!
mm my vb skills are not that good, more of a c# person. but here goes
If DetailsView1.FooterRow != null Then
Dim commandRowIndex as Integer = DetailsView1.Rows.Count - 1
Dim commandRow as DetalsViewRow = CType( DetailsView1.Rows( commandRowIndex ), DetailsViewRow)
Dim cell as DataControlFieldCell = CType( commandRow.Controls(0), DataControlFieldCell )
For Each ctl As Control In cell.Controls
Dim lnk as LinkButton = CType( ctl, LinkButton )
if lnk != null then
If lnk.CommandName = "Delete" Then
lnk.OnClientClick = " return confirm( 'Delete?' ); "
End If
End If
Next
End If
If DetailsView1.FooterRow != null Then
Dim commandRowIndex as Integer = DetailsView1.Rows.Count - 1
Dim commandRow as DetalsViewRow = CType( DetailsView1.Rows( commandRowIndex ), DetailsViewRow)
Dim cell as DataControlFieldCell = CType( commandRow.Controls(0), DataControlFieldCell )
For Each ctl As Control In cell.Controls
Dim lnk as LinkButton = CType( ctl, LinkButton )
if lnk != null then
If lnk.CommandName = "Delete" Then
lnk.OnClientClick = " return confirm( 'Delete?' ); "
End If
End If
Next
End If
in case the != doesnt work ( not equal ) then use <>
ps a good compairson site for vb.net versus c# is
http://www.harding.edu/USER/fmccown/WWW/vbnet_csharp_comparison.html
ps a good compairson site for vb.net versus c# is
http://www.harding.edu/USER/fmccown/WWW/vbnet_csharp_comparison.html
ASKER
Getting close!
how is:
protected void DetailsView1_ItemCreated(o bject sender, EventArgs e)
converted to VB?
how is:
protected void DetailsView1_ItemCreated(o
converted to VB?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
example (bear in mind index for cells depends in which colum you have the command button )
If e.Row.RowType = DataControlRowType.DataRow
Dim lb As LinkButton
lb = e.Row.Cells(0).Controls(0)
lb.Attributes.Add("onclick
End If
or c#
if ( e.Row.RowType == DataControlRowType.DataRow
{
LinkButton lb =(LinkButton) e.Row.Cells[0].Controls[0]
if ( lb != null )
{
lb.Attributes.Add("onclick
}
}