Display prompt for update and deletion of gridview

Source: Internet
Author: User

In the past, when ASP. NET 1.x was used, it often encountered prompts for handling list controls.ASP. net2.0Yes, useGridviewAfter similar things are completed, the display prompt information is updated and deleted, and sqldatasource is used after confirmation.
Completed database operations

<% @ Page Language = "C #" %>

<SCRIPT runat = "server">

Void gridview1_rowcommand (Object sender, gridviewcommandeventargs
E)
{
Switch (E. commandname. tolower ())

{
Case "edit ":
Gridview1.columns [0]. Visible =
False;
Gridview1.columns [1]. Visible =
True;
Break;
Case "Update ":

Case "delete ":
Case "cancel ":

Gridview1.columns [0]. Visible = true;

Gridview1.columns [1]. Visible = false;
Break;

Default:
// Do nothing.
Break;

}
}

Void gridview1_rowupdating (Object sender, gridviewupdateeventargs
E)
{
Int Index = gridview1.editindex;
Gridviewrow
Row = gridview1.rows [Index];

Textbox firstnametextbox =
(Textbox) Row. cells [1]. findcontrol ("firstnametextbox ");

String firstname = "";
If (firstnametextbox! =
Null)
{
Firstname = firstnametextbox. text;

}

Textbox lastnametextbox =
(Textbox) Row. cells [2]. findcontrol ("lastnametextbox ");

String lastname = "";
If (lastnametextbox! =
Null)
{
Lastname = lastnametextbox. text;

}

Parameter lastnameparameter = new parameter ("au_lname ",
Typecode. String, lastname );
Parameter firstnameparameter = new
Parameter ("au_fname", typecode. String, firstname );

Sqldatasource1.updateparameters. Clear ();

Sqldatasource1.updateparameters. Add (lastnameparameter );

Sqldatasource1.updateparameters. Add (firstnameparameter );
}

Void gridview1_rowdeleting (Object sender, gridviewdeleteeventargs
E)
{
Sqldatasource1.Deleteparameters. Clear ();
}


</SCRIPT>

<HTML xmlns = "http://www.w3.org/1999/xhtml"
>
<Head runat = "server">
<Title> display prompt information for update and deletion of gridview-
Wang Zhi-2006 </title>
</Head>
<Body>
<Form
Id = "form1" runat = "server">
<Div>
<Asp: gridview
Id = "gridview1" runat = "server"
Performanceid = "sqlperformance1"
Autogeneratecolumns = "false" datakeynames = "au_id"
Onrowcommand = "gridview1_rowcommand" onrowupdating = "gridview1_rowupdating"
Onrowdeleting = "gridview1_rowdeleting">

<Columns>

<Asp: templatefield>

<Itemtemplate>
<Asp: linkbutton id = "edit"
Runat = "server"
Commandname = "edit"> edit </ASP: linkbutton>

</Itemtemplate>

</ASP: templatefield>
<Asp: templatefield
Visible = "false">

<Itemtemplate>
<Asp: linkbutton id = "Update"
Runat = "server" commandname = "Update" onclientclick = "Return
Confirm ('Are you sure you want to update? '); "> Update </ASP: linkbutton> & nbsp;

<Asp: linkbutton id = "delete" runat = "server" commandname = "delete"
Onclientclick = "Return
Confirm ('Confirm to delete'); "> Delete </ASP: linkbutton> & nbsp;

<Asp: linkbutton id = "cancel" runat = "server"
Commandname = "cancel"> cancel </ASP: linkbutton>

</Itemtemplate>

</ASP: templatefield>
<Asp: templatefield
Headertext = "last name">

<Itemtemplate>
<% # Eval ("au_lname ")
%>
</Itemtemplate>

<Edititemtemplate>
<Asp: textbox
Id = "lastnametextbox" text = '<% # eval ("au_lname ")
%>'
Width = "175"
Runat = "server"/>

<Br/>
<Asp: requiredfieldvalidator
Id = "lastnamerequiredvalidator" controltovalidate = "lastnametextbox"

Errormessage = "Please enter a last name ."
Validationgroup = "namegroup" runat = "server"/>

</Edititemtemplate>

</ASP: templatefield>


<Asp: templatefield headertext = "first name">

<Itemtemplate>
<% # Eval ("au_fname ")
%>
</Itemtemplate>

<Edititemtemplate>
<Asp: textbox
Id = "firstnametextbox" text = '<% # eval ("au_fname ")
%>'
Width = "175"
Runat = "server"/>

<Br/>
<Asp: requiredfieldvalidator
Id = "firstnamerequiredvalidator"
Controltovalidate = "firstnametextbox"

Errormessage = "Please enter a first name." validationgroup = "namegroup"
Runat = "server"/>

</Edititemtemplate>

</ASP: templatefield>
</Columns>

</ASP: gridview>
<Asp: sqldatasource id = "sqlperformance1"
Runat = "server" connectionstring = "<% $ connectionstrings: pubs2000
%>"
Providername = "<% $
Connectionstrings: pubs2000.providername %> "selectcommand =" select au_id,
Au_lname, au_fname from authors"
Updatecommand = "Update authors
Set au_lname = @ au_lname, au_fname = @ au_fname where (au_id = @ au_id )"

Deletecommand = "delete from authors where (au_id =
@ Au_id) ">
</ASP: sqldatasource>
</Div>

</Form>
</Body>
</Html>

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.