How to get the data bound to the current item in the repeater event?

Source: Internet
Author: User

How to get the data bound to the current item in the repeater event?

I use repeater to implement a message book. In the itemtemplate of my repeater (ID: RP1), there is a linkbutton (ID: delbutton) used to delete the message ).

Message Base table structure
Table message
(
ID,
Username,
Message
)

I want to use a client script to confirm the deletion. A script dialog box is displayed before deletion. "Are you sure you want to delete the username message ?" Here, the username is from the bound data of the repeater. The bound username values for different items are also different.

Go through acewang (guest core * Inside !) With the help of SVG (Ben), my final implementation is as follows:

Display page:

<Script language = "JavaScript">
<! --
Function confirm_del (username)
{
Return confirm ('Are you sure you want to delete '+ username +? ');
}
// -->
</SCRIPT>

<Asp: repeater id = "repguestbook" runat = "server">
<Itemtemplate>
....
....
<Asp: linkbutton id = "delbutton" runat = "server" oncommand = "del_click" commandname = "Del" commandargument = '<% # databinder. eval (container. dataitem, "ID") %> '> delete a message </ASP: linkbutton>
....
....
</Itemtemplate>
</ASP: repeater>

Code Page:

Private void initializecomponent ()
{
....
This. rp1.itemdatabound + = new system. Web. UI. webcontrols. repeateritemeventhandler (this. repeaterincluitemdatabound );
....
}

Private void repeaterincluitemdatabound (Object source, system. Web. UI. webcontrols. repeateritemeventargs E)
{
If (E. Item. itemtype = listitemtype. item)
{
Linkbutton lB = (linkbutton) E. Item. findcontrol ("mylb ");
Lb. attributes ["onclick"] = "javascript: Return confirm_del ('" + databinder. eval (E. item. dataitem, "username") + "'); Return false ;";
// Lb. attributes ["onclick"] = "javascript: Return confirm_del ('" + (datarowview) (E. item. dataitem) ["username"] + "'); Return false ;";
}

}

The onclick implementation above demonstrates two implementation methods. (The first one is commented out .)
In actual application, only one type is needed.

Databinder. eval (E. Item. dataitem, "username") is easy to use.
(Datarowview) (E. Item. dataitem) ["username"] This method is highly efficient.

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.