How to Use the rowdatabound event to modify the field value in the data source before displaying it in the gridview Control

Source: Internet
Author: User

Before rendering the gridview control, each row in the control must be bound to a record in the data source. When you bind a data row (represented by a gridviewrow object) to the data in the gridview control, the rowdatabound event is triggered. This allows you to provide an event processing method, that is, a custom routine is executed every time this event occurs (such as modifying the value of the data bound to the row ).

The gridviewroweventargs object is passed to the event processing method so that you can access the attributes of the row being bound. To access a specific cell in the row, use the cells attribute of the gridviewroweventargs object. You can use the rowtype attribute to determine which row type is being bound (header row, data row, and so on ).
Protected void gridview1_rowdatabound (Object sender, gridviewroweventargs E)
{
If (E. Row. rowtype = datacontrolrowtype. datarow)
{
Label lblname = (Label) E. Row. findcontrol ("lblname ");
Label lblmoney = (Label) E. Row. findcontrol ("lblmoney ");
Label lblzdot = (Label) E. Row. findcontrol ("lblzdot ");
Label lblsdot = (Label) E. Row. findcontrol ("lblsdot ");
Profilecommon P = profile. getprofile (lblname. Text );
Lblmoney. Text = P. inmoney. tostring ();
Lblzdot. Text = P. dcount. tostring ();
Lblsdot. Text = P. scount. tostring ();
}
}

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.