CommandName of the button LinkButton event in the GridView

Source: Internet
Author: User
I. <asp: LinkButton ID = "LinkButton1" runat = "server" CommandName = "updateState" Text = "available"
CommandArgument = '<% # Eval ("Roleid") %>'/>

Protected void GVrole_RowCommand (object sender, GridViewCommandEventArgs e)
{
If (e. CommandName = "updateState ")
{

LinkButton Lb = (LinkButton) sender;
Lb. Text = "disabled ";
}}

LinkButton can trigger CommandName, Button, imgeButon cannot trigger

Ii. <asp: ButtonField CommandName = "ShowTeam" HeaderText = "Team Info"
Text = "Team Info"/>
Protected void GVrole_RowCommand (object sender, GridViewCommandEventArgs e)
{
If (e. CommandName = "updateState ")
{
Page. Alert ("updateState ");

}
If (e. CommandName = "ShowTeam ")
{
Page. Alert (e. CommandArgument. ToString (); // e. CommandArgument obtains the index of the current row.
Int ClientID = Convert. ToInt32 (ClientGridview. DataKeys [index]. Value. ToString ());
Obtain the corresponding data

 

(LinkButton) e. CommandSource). Text = "disabled"; e. CommandSource obtains the event source, that is, LinkButton, And you can operate on the attributes of this linkButton}

}

 

Protected void GVrole_RowCommand (object sender, GridViewCommandEventArgs e)
{
If (e. CommandName = "updateState ")

 

If (LinkButton) e. CommandSource). Text. ToString () = "disabled ")
{

(LinkButton) e. CommandSource). Text = "available ";
}
Else

 

 

3. Configure the event using the onCommand command

 

<Asp: Button ID = "garbage" OnCommand = "garbage" OnClientClick = "return confirm ('Are you sure you want to set it to spam? '); "Runat =" server "Text =" spam "visible =" false "CommandName =" garbage "CommandArgument =' <% # Eval (" ID ") %> '/>

 

Protected void Refer (object sender, CommandEventArgs e)
{
Int id = Convert. ToInt32 (e. CommandArgument );

Using (DataClassesDataContext db = new DataClassesDataContext ())
{
Var QuSupport = db. QuestionSupport. FirstOrDefault (q => q. ID = id );

If (QuSupport! = Null)
{
Content. Text = QuSupport. SupportContent; // get Content
QuSupport. IsRefereed = true; // set the reference to true.
Try
{
Db. SubmitChanges ();
}
Catch (Exception)
{

Throw;
}
}
}

}

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.