首页 > 开发 > 综合 > 正文

在datagrid中删除时确定

2024-07-21 02:16:46
字体:
来源:转载
供稿:网友

最大的网站源码资源下载站,

<%@ 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
        dim mydeletebutton as button
            mydeletebutton = e.item.findcontrol("btndelete")
         mydeletebutton.attributes.add("onclick","return confirm('are you sure you want to delete this company?');")

        case 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>

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表