1. Bind a primary key in the database
Front-end code:
<Itemtemplate>
<Asp: imagebutton id = "ibtnupdate" runat = "server" commandargument = '<% # eval ("studentnum") %>'
Commandname = "edit"/>
</Itemtemplate>
You can obtain the primary key of the row through the rowcommand event of the gridview, and then obtain the row data.
Protected void gvselecttask_rowcommand (Object sender, gridviewcommandeventargs E)
{
String temp = E. commandargument. tostring (). Trim ();
// String [] num = temp. Split (',');
String tag = E. commandname. tostring (). Trim ();
// If (TAG = "edit ")
//{
// Creativestudio. Common. Alert. gohref ("selecttaskedit. aspx? Studentn = "+ num [0] +" & teachern = "+ num [1] + "");
//}
// Else if (TAG = "delete") // It is not necessary to delete student records when deleting Course Selection records
//{
// Staskbll. Delete (Num [0]);
// BIND ();
//}
}
2. If the primary key is involved in two fields or you want to bind the two tables with the primary key at the same time, the usage is
Front-end code:
<Itemtemplate>
<Asp: imagebutton id = "ibtnupdate" runat = "server" commandargument = '<% # eval ("studentnum") + "," + eval ("teachernum") %>'
Commandname = "edit"/>
</Itemtemplate>
You can also obtain one row of data in a table or one row of data in both tables.
Protected void gvselecttask_rowcommand (Object sender, gridviewcommandeventargs E)
{
String temp = E. commandargument. tostring (). Trim ();
String [] num = temp. Split (',');
String tag = E. commandname. tostring (). Trim ();
// If (TAG = "edit ")
//{
// Creativestudio. Common. Alert. gohref ("selecttaskedit. aspx? Studentn = "+ num [0] +" & teachern = "+ num [1] + "");
//}
// Else if (TAG = "delete") // It is not necessary to delete student records when deleting Course Selection records
//{
// Staskbll. Delete (Num [0]);
// BIND ();
//}
}
Now I only understand these two usages. If I have a new understanding and a new usage, I will continue to add ......
(Conversion) commandargument usage