The first column of the gridview is buttonfield, and the field name is "delete". If you want to delete it, a confirmation box is displayed. Otherwise, how should I write the result?

Source: Internet
Author: User

Problem:
The first column of the gridview is buttonfield, and the field name is "delete". If you want to delete it, a confirmation box is displayed. Otherwise, how should I write the result?
Solution:
1. Click the shortcut arrow of the gridview and select 'edit column '.
2. Add a buttonfiled, set headtext (for display) in the property box on the right, and define a commandname (for the action triggered after you click)
3. Click 'convert to template columns 'in the lower right corner. OK.
4. Right-click the gridview, 'edit template' -- 'column [..] -- your previously defined headtext'. Can you see your button in itemtemplate? Point, there is an item 'onclientclick' in the property, put "javascript: Return confirm ('Do you really want to delete it? '); "Paste in.
5. Complete the functions you need.
6. If you want to click the button to trigger other events, you can write in detail in the rowcommand event...
Protected void gridview1_rowcommand (Object sender, gridviewcommandeventargs E)
{
If (E. commandname = "mybtnclicked") // The commandname you defined earlier
{
Response. Write ("kkk clicked ");
}
}

1. In Step 4 above, you can see the small arrow in the upper right corner of your button in itemtemplate. verygood, click 'edit databings '...
2. Have you seen the binding at this level? Bind commandargument to the field you want to operate... (Select from the drop-down list on the right)
3. OK. Now you can call the following method:
------------------
Protected void gridview1_rowcommand (Object sender, gridviewcommandeventargs E)
{
If (E. commandname = "mybtnclicked ")
{
Response. Write ("You Wanted" + E. commandargument. tostring ());
}
}
------------------
You just want to get the content in the cell in the result set. Now you want to bind the content to the commandargument, so you don't need to index any cell []. text (you need findcontrol for complicated cells, huh, huh)

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.