Add confirmation dialog box in the DataGrid

Source: Internet
Author: User

Add confirmation dialog box in the DataGrid

Http: // lucky_elove.www1.dotnetplayground.com/

It is a friendly practice to confirm before deleting data. In this article, we will discuss how to use the templatecolumn and button server controls to implement this function.

View examples

Deleteit. aspx

<Meta content = "Microsoft Visual Studio. net 7.0 "name =" generator "> <meta content =" Visual Basic 7.0 "name =" code_language "> <meta content =" JavaScript "name =" vs_defaultclientscript "> <meta content = "http://schemas.microsoft.com/intellisense/ie5" name = "vs_targetschema"> <label id = "label1" runat = "server"> </label> <br/>

Code: deleteit. aspx. VB

Imports system. web <br/> imports system. collections <br/> imports system. data <br/> imports system. data. oledb <br/> imports system. web. UI. webcontrols <br/> public class deleteit <br/> inherits system. web. UI. page <br/> protected withevents label1 as system. web. UI. webcontrols. label <br/> protected withevents mydatagrid as system. web. UI. webcontrols. code generated by the DataGrid <br/> # region "Web Form Designer "<Br/> 'This call is required by the web form designer. <Br/> <system. diagnostics. debuggerstepthrough> private sub initializecomponent () <br/> end sub <br/> private sub page_init (byval sender as system. object, byval e as system. eventargs) handles mybase. init <br/> 'codegen: This method is required by the web form designer. <br/> 'do not use the code editor to modify it. <Br/> initializecomponent () <br/> end sub <br/> # End Region <br/> sub page_load (byval sender as object, byval e as eventargs) handles mybase. load <br/> mydatagrid. headerstyle. font. bold = true <br/> mydatagrid. headerstyle. horizontalalign = horizontalalign. center <br/> mydatagrid. columns (0 ). headertext = "operation" <br/> mydatagrid. columns (1 ). headertext = "title" <br/> mydatagrid. columns (2 ). headertext = "Release Date" <Br/> if not ispostback then <br/> dim strcn as string = "provider = Microsoft. jet. oledb.4.0; Data Source = "+ server. mappath ("test. mdb ") <br/> dim strsql as string <br/> strsql =" select top 15 objectguid, title, createdate from document order by createdate DESC "<br/> dim cn as new oledbconnection (strcn) <br/> CN. open () <br/> dim cmd as new oledbcommand (strsql, CN) <br/> mydatagrid. datasource = cmd. E Xecutereader (commandbehavior. closeconnection) <br/> mydatagrid. databind () <br/> cmd. dispose () <br/> cmd = nothing <br/> CN. close () <br/> CN. dispose () <br/> Cn = nothing <br/> end if <br/> end sub <br/> sub datagrid_itemcreated (byval sender as object, byval e as datagriditemeventargs) _ <br/> handles mydatagrid. itemcreated <br/> select case e. item. itemtype <br/> case listitemtype. item, listitemtype. Alternatingitem, listitemtype. edititem <br/> dim mydeletebutton as button <br/> mydeletebutton = E. item. findcontrol ("btndelete") <br/> mydeletebutton. TEXT = "delete this row" <br/> mydeletebutton. attributes. add ("onclick", "Return confirm ('Do you really want to delete the nth '_ <br/> + E. item. itemindex. tostring + "OK? '); ") <Br/> end select <br/> end sub <br/> private sub mydatagrid_itemcommand (byval source as object, _ <br/> byval e as system. web. UI. webcontrols. datagridcommandeventargs) _ <br/> handles mydatagrid. itemcommand <br/> response. write ("What you want to delete is:" + E. item. cells (1 ). text + "") <br/> E. item. backcolor = system. drawing. color. ivory <br/> end sub <br/> end class <br/> </system. diagnostics. debuggerstepthrough>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.