When you click the LinkButton in DataList, remove the button's text value

Source: Internet
Author: User
When you click the LinkButton in DataList, remove the button's text value


2011-01-07 09:55:00|  Category: ASP.net learning | Tags: learning | reporting | font size subscription
Many times, when you bind a LinkButton in our DataList, you need to remove its text value when clicked, and the value method is as follows:


There is a commandargument attribute in LinkButton that is used to pass parameters in command commands, so when binding the data, the data to be fetched is bound to the CommandArgument in the click of the argument in the event command so that You can remove the passed parameter in the Click event;


The code on the DataList is as follows:


<asp:datalist id= "DataList1" runat= "Server" datasourceid= "SqlDataSource3"
height= "29px" repeatcolumns= "2" showfooter= "false" showheader= "false"
Forecolor= "#666666" onselectedindexchanged= "datalist1_selectedindexchanged"
repeatdirection= "Horizontal" >
<itemstyle wrap= "True"/>
<ItemTemplate>
<asp:linkbutton id= "LinkButton9" runat= "Server" onclick= "Linkbutton9_click"
text= ' <%# eval ("Processor family")%> ' forecolor= ' #666666 ' commandargument= ' <%# Eval ("Processor family")%> ' ></asp: Linkbutton>
</ItemTemplate>
</asp:DataList>


Click the code in the event as follows:


protected void Linkbutton9_click (object sender, EventArgs e)
{
LinkButton btn = (LinkButton) sender;
Response.Write ("<script Language=javascript>alert" ("+btn"). Text.tostring () + "') </script>");
}

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.