R
RN1
I have a DataList which displays the first & last name of users as
links (LinkButtons). When the links are clicked, 2 textboxes appear -
one with the first name & the other with the last name - for the users
to edit. At the same time, 3 LinkButtons - Cancel, Update & Delete
also appear. I want to add a JavaScript confirm dialog to the Delete
LinkButton. This is how I tried it in the OnItemDataBound event
function of the DataList:
----------------------------------
<script runat="server">
Sub BindItem(...........)
If (dlNetUsers.EditItemIndex <> -1) Then
If (ea.Item.ItemType = ListItemType.AlternatingItem Or
ea.Item.ItemType = ListItemType.Item) Then
Dim lnkDel As LinkButton
Dim lnkUID As LinkButton
lnkDel = CType(ea.Item.FindControl("lnkDelete"),
LinkButton)
lnkUID = CType(ea.Item.FindControl("lnkUserID"),
LinkButton)
lnkDel.Attributes.Add("OnClick", "if(!confirm('Delete
" & lnkUID.Text & "?')) return false;")
End If
End If
End Sub
</script>
<form runat="server">
<aspataList ID="dlUsers" OnItemDataBound="BindItem" runat="server">
<ItemTemplate>
<asp:LinkButton ID="lnkUserID" CommandArgument='<%#
Container.DataItem("UserID") %>' CommandName="Edit" runat="server"><%#
Container.DataItem("FirstName") %> <%#
Container.DataItem("LastName") %></asp:LinkButton>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtFName" Text='<%# Container.DataItem("FirstName")
%>' runat="server"/>
<asp:TextBox ID="txtLName" Text='<%# Container.DataItem("LastName")
%>' runat="server"/>
<asp:LinkButton ID="lnkCancel" CommandName="Cancel" Text="Cancel"
runat="server"/>
<asp:LinkButton ID="lnkUpdate" CommandName="Update" Text="Update"
runat="server"/>
<asp:LinkButton ID="lnkDelete" CommandName="Delete" Text="Delete"
runat="server"/>
</EditItemTemplate>
</aspataList>
</form>
----------------------------------
The problem is when I click any of the names, the following error gets
generated:
Object reference not set to an instance of an object.
pointing to the line lnkDel.Attributes.Add........
What am I doing wrong here?
Thanks,
Ron
links (LinkButtons). When the links are clicked, 2 textboxes appear -
one with the first name & the other with the last name - for the users
to edit. At the same time, 3 LinkButtons - Cancel, Update & Delete
also appear. I want to add a JavaScript confirm dialog to the Delete
LinkButton. This is how I tried it in the OnItemDataBound event
function of the DataList:
----------------------------------
<script runat="server">
Sub BindItem(...........)
If (dlNetUsers.EditItemIndex <> -1) Then
If (ea.Item.ItemType = ListItemType.AlternatingItem Or
ea.Item.ItemType = ListItemType.Item) Then
Dim lnkDel As LinkButton
Dim lnkUID As LinkButton
lnkDel = CType(ea.Item.FindControl("lnkDelete"),
LinkButton)
lnkUID = CType(ea.Item.FindControl("lnkUserID"),
LinkButton)
lnkDel.Attributes.Add("OnClick", "if(!confirm('Delete
" & lnkUID.Text & "?')) return false;")
End If
End If
End Sub
</script>
<form runat="server">
<aspataList ID="dlUsers" OnItemDataBound="BindItem" runat="server">
<ItemTemplate>
<asp:LinkButton ID="lnkUserID" CommandArgument='<%#
Container.DataItem("UserID") %>' CommandName="Edit" runat="server"><%#
Container.DataItem("FirstName") %> <%#
Container.DataItem("LastName") %></asp:LinkButton>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtFName" Text='<%# Container.DataItem("FirstName")
%>' runat="server"/>
<asp:TextBox ID="txtLName" Text='<%# Container.DataItem("LastName")
%>' runat="server"/>
<asp:LinkButton ID="lnkCancel" CommandName="Cancel" Text="Cancel"
runat="server"/>
<asp:LinkButton ID="lnkUpdate" CommandName="Update" Text="Update"
runat="server"/>
<asp:LinkButton ID="lnkDelete" CommandName="Delete" Text="Delete"
runat="server"/>
</EditItemTemplate>
</aspataList>
</form>
----------------------------------
The problem is when I click any of the names, the following error gets
generated:
Object reference not set to an instance of an object.
pointing to the line lnkDel.Attributes.Add........
What am I doing wrong here?
Thanks,
Ron