首页 > 开发 > 综合 > 正文

关于如何 确认删除的另外一个办法。

2024-07-21 02:16:52
字体:
来源:转载
供稿:网友
<pre>
<%@ page language="vb" %>
<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

    ' add a client click event to the button
        page.registeronsubmitstatement("onsubmit", "if(button == 'delete company')return confirm('are you sure you want to delete this company?');")

    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 mydatagrid_delete(sender as object, e as datagridcommandeventargs)
    label1.text = "hey, you can't delete " & mydatagrid.datakeys(cint(e.item.itemindex)) & "!"
    end sub

    sub mydatagrid_itemcreated(sender as object, e as datagriditemeventargs)

        select case e.item.itemtype
            case listitemtype.item, listitemtype.alternatingitem
        dim mytablecell as tablecell
        mytablecell = e.item.cells(0)
            dim mydeletebutton as button
            mydeletebutton = mytablecell.controls(0)
             mydeletebutton.attributes.add("onclick","button=this.value")
        
        'notice that it is cell 1 instead of 0
        mytablecell = e.item.cells(1)
            mydeletebutton = mytablecell.controls(0)
             mydeletebutton.attributes.add("onclick","button=this.value")

        end select

    end sub

</script>

</head>
<body>
    
    <asp:label id="label1" runat="server" />
    
    <form runat=server>
       <asp:datagrid id="mydatagrid"
           datakeyfield="name"
           autogeneratecolumns="true"
       ondeletecommand="mydatagrid_delete"
       onitemcreated="mydatagrid_itemcreated"
           runat="server">

    <columns>
        <asp:buttoncolumn text="no onsubmit" commandname="nosubmit" buttontype="pushbutton"/>
        <asp:buttoncolumn text="delete company" commandname="delete" buttontype="pushbutton"/>
        </columns>

       </asp:datagrid>
       <p>

       <asp:textbox id="tokentextbox" runat="server" columns="40" text="the required field validator will not fire" />
       <asp:requiredfieldvalidator id="tokentvalidator" runat="server" controltovalidate="tokentextbox" />
    </form>
</body>
</html>
</pre>
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表