Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8488279
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T21:29:15+00:00 2026-06-10T21:29:15+00:00

Q> I want to show a GridView button’s text as hard coded and a

  • 0

Q> I want to show a GridView button’s text as hard coded and a event to fire on button click. How to achieve this ?

Till now I’ve been able to come this far

GridView Sample

But I want to show button text as Read or Delete not the value in the Read/Delete column.
The code I’ve used

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
DataKeyNames="MID" DataSourceID="inbox" EnableModelValidation="True" 
onselectedindexchanged="GridView1_SelectedIndexChanged">
<Columns>
<asp:ButtonField ButtonType="Button" DataTextField="MID" HeaderText="Read" 
  Text="Read" />
<asp:BoundField DataField="MID" HeaderText="MID" InsertVisible="False" 
  ReadOnly="True" SortExpression="MID" />
<asp:BoundField DataField="sender" HeaderText="sender" 
  SortExpression="sender" />
<asp:BoundField DataField="subject" HeaderText="subject" 
  SortExpression="subject" />
<asp:BoundField DataField="on" HeaderText="on" SortExpression="on" />
<asp:ButtonField ButtonType="Button" DataTextField="MID" HeaderText="Delete" 
  Text="Delete" />
</Columns>
</asp:GridView>

<asp:SqlDataSource ID="inbox" runat="server" 
ConnectionString="<%$ ConnectionStrings:connectionString %>" 
SelectCommand="SELECT [MID], [sender], [subject], [on] FROM [mail]">
</asp:SqlDataSource>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T21:29:16+00:00Added an answer on June 10, 2026 at 9:29 pm

    If you want the text to appear as “Delete” or “Read”, then simply don’t set the DataTextField property to use the MID property of the result and instead set the CommandName property as so:

    <asp:ButtonField ButtonType="Button" CommandName='<%#Eval("MMID")%>' HeaderText="Delete" 
      Text="Delete" />
    

    As far as handling the OnClick event of the buttons, you can handle the OnRowCommand event on the GridView as so:

    <asp:GridView ID="GridView1" runat="server" OnRowCommand="GridView_RowCommand" AutoGenerateColumns="False" 
    

    Now add the code behind:

    protected void GridView_RowCommand(Object sender, GridViewCommandEventArgs e)
    {
    
      string MMID = e.CommandName;
      if( (e.CommandSource as ButtonField).Text=="Delete")
      {
                 //oh, I should delete this MMID
      }
    }    
    

    UPDATE

    Above code does not work. ButtonField is as useful as nipples are to men. Instead use an ItemTemplateField as so:

     <asp:TemplateField>
         <ItemTemplate>
             <asp:Button ID="btn" runat="server" CommandName="Delete" CommandArgument='<%#Eval("MID") %>'
                        Text="Delete" />
         </ItemTemplate>
     </asp:TemplateField>
    

    Then the GridView_RowCommand becomes this:

    protected void GridView_RowCommand(Object sender, GridViewCommandEventArgs e)
        {
            string mid = e.CommandArgument.ToString();
            // If multiple buttons are used in a GridView control, use the
            // CommandName property to determine which button was clicked.
            if (e.CommandName == "Delete")
            {
    
            }
        }    
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to show a thumbnail image inside a gridview instead of the text.
Have a gridview control which will show X amount of rows. I want to
hii I want show a pop up Dialog box when i click on to
I want to show the datatable header to gridview header. My datatable have dynamic
I want to show items in my gridview as a 5 across and a
I want to show data in my database with Linq in gridview but I
I want to show icon that associated with file type. Something like this But
i have an gridview control with a comment text, link button, and an invisible
I want to show some progress animation in my textbox. Becoz when i click
...I want to Show the 'delete' button when user is an admin, and show

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.