I. Parts of aspx
Code ;
<Asp: DataGrid id = "mydatagrid" runat = "server" width = "100%" font-names = "verdana" bordercolor = "black"
Borderwidth = "1px" cellpadding = "3" font-name = "verdana" font-size = "8pt" headerstyle-backcolor = "# aaaadd"
Alternatingitemstyle-backcolor = "# eeeeee" horizontalalign = "center" autogeneratecolumns = "false">
<Alternatingitemstyle backcolor = "# f7fbff"> </alternatingitemstyle>
<Headerstyle font-bold = "true" horizontalalign = "center" backcolor = "#99 CCFF">
<Columns>
<Asp: boundcolumn datafield = "tempsemester" headertext = "term">
<Headerstyle width = "25%" type = "codeph" text = "/codeph">
</ASP: boundcolumn>
<Asp: boundcolumn datafield = "examdate" headertext = "test time">
<Headerstyle width = "25%" type = "codeph" text = "/codeph">
</ASP: boundcolumn>
<Asp: boundcolumn datafield = "examname" headertext = "times">
<Headerstyle width = "35%" type = "codeph" text = "/codeph">
</ASP: boundcolumn>
<Asp: boundcolumn headertext = "operation">
<Itemstyle horizontalalign = "center" width = "15%"> </itemstyle>
</ASP: boundcolumn>
<Asp: hyperlinkcolumn visible = "false" text = "& lt; IMG src = & quot ;.. /.. /images/modi.gif & quot; border = & quot; 0 & quot; Alt = & quot; Modify & quot; & gt ;"
Datanavigateurlfield = "examnameid" datanavigateurlformatstring = "javascript: newwin ('modiexamset. aspx? Examnameid = {0 }')"
Headertext = "edit"> </ASP: hyperlinkcolumn>
<Asp: buttoncolumn visible = "false" text = "& lt; IMG src = & quot ;.. /.. /images/del.gif & quot; border = & quot; 0 & quot; Alt = & quot; Delete & quot; onclick = & quot; return confirm ('Are you sure you want to delete this address book? '); & Quot; & gt ;"
Headertext = "delete" commandname = "delete"> </ASP: buttoncolumn>
<Asp: boundcolumn visible = "false" datafield = "examnameid">
<Itemstyle horizontalalign = "center"> </itemstyle>
</ASP: boundcolumn>
<Asp: boundcolumn visible = "false" datafield = "examtype">
<Itemstyle horizontalalign = "center"> </itemstyle>
</ASP: boundcolumn>
</Columns>
</ASP: DataGrid>
2. Events called;
This. mydatagrid. deletecommand + = new system. Web. UI. webcontrols. datagridcommandeventhandler (this. mydatagrid_deletecommand );
This. mydatagrid. itemdatabound + = new system. Web. UI. webcontrols. datagriditemeventhandler (this. mydatagrid_itemdatabound );
3. Control Multiple buttons in a cell
Private void mydatagrid_itemdatabound (Object sender, system. Web. UI. webcontrols. datagriditemeventargs E)
{
If (E. Item. itemindex> = 0 ){
If (E. Item. cells [7]. Text. Trim () = "C "){
Tablecell optd = (tablecell) E. Item. controls [3];
// Pop-up editing
Tablecell opedit = (tablecell) E. Item. controls [4];
Optd. Controls. Add (opedit. controls [0]);
// Delete button
Tablecell opdel = (tablecell) E. Item. controls [5];
Optd. Controls. Add (opdel. controls [0]);
}
}
}
4. Click Delete to execute the operation;
Private void mydatagrid_deletecommand (Object source, system. Web. UI. webcontrols. datagridcommandeventargs E)
{
String examnameid = E. Item. cells [6]. Text. Trim ();
String strsql = "delete examsubject where examnameid =" + examnameid;
Strsql + = ";";
Strsql + = "delete examname where examnameid =" + examnameid;
If (db. insertmoredb (strsql ))
{
Response. Write (JS. inforerror ("test time deleted successfully! "));
}
Else {
Response. Write (JS. inforerrorback ("Hello, teacher! The score of this test cannot be deleted because it has been entered. If you need to delete this test, delete the score of this test first. Thank you! "));
}
Examinit ();
}