(Conversion) commandargument usage

Source: Internet
Author: User

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

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.