一个datagrid 删除确认例子
2024-07-21 02:22:03
供稿:网友
<%@ page language="vb" debug="true" %>
<html>
<head>
<script language="vb" runat="server">
sub page_load(sender as object, e as eventargs)
if not ispostback then
dim values as new arraylist()
values.add(new positiondata("microsoft", "msft"))
values.add(new positiondata("intel", "intc"))
values.add(new positiondata("dell", "dell"))
mydatagrid.datasource = values
mydatagrid.databind()
end if
end sub
public class positiondata
private myname as string
private myticker as string
public sub new(newname as string, newticker as string)
me.myname = newname
me.myticker = newticker
end sub
public readonly property name() as string
get
return myname
end get
end property
public readonly property ticker() as string
get
return myticker
end get
end property
end class
sub datagrid_itemcreated(sender as object, e as datagriditemeventargs)
select case e.item.itemtype
case listitemtype.item, listitemtype.alternatingitem
dim mydeletebutton as button
mydeletebutton = e.item.findcontrol("btndelete")
mydeletebutton.attributes.add("onclick","return confirm('are you sure you want to delete this company?');")
end select
end sub
sub datagrid_deleterow(sender as object, e as eventargs)
label1.text = "hey, you can't delete that company!"
end sub
</script>
</head>
<body>
<asp:label id="label1" runat="server" />
<form runat=server>
<asp:datagrid id="mydatagrid"
onitemcreated="datagrid_itemcreated"
datakeyfield="name"
autogeneratecolumns="true"
runat="server">
<columns>
<asp:templatecolumn headertext="delete?">
<itemtemplate>
<asp:button id="btndelete" onclick="datagrid_deleterow" runat="server" text="delete row" />
</itemtemplate>
</asp:templatecolumn>
</columns>
</asp:datagrid>
<p>
</form>
</body>
</html>