Solved

ASP.net Change button text for each line of GridView

Posted on 2015-01-20
2
388 Views
Last Modified: 2015-01-20
Hi

I have built the a web page with the GridView shown below (markup of one button further). I want to change the text on the buttons for each line and hide  certain buttons too. How do I do this?

1
       <asp:TemplateField HeaderText="Undecided" HeaderStyle-Font-Size ="Small"
                                            ControlStyle-Font-Bold ="false" ControlStyle-Forecolor ="SlateGray"
                                            ControlStyle-Font-Size ="Smaller">
                    <ItemTemplate>
                        <asp:Button ID="Button8" runat="server"
                      CommandName="MyButton3"
                      CommandArgument="<%# CType(Container,GridViewRow).RowIndex %>"
                      Text="Undecided" />
                    </ItemTemplate>
                    <ControlStyle Font-Bold="False" Font-Size="Smaller" ForeColor="SlateGray" />
                    <HeaderStyle Font-Size="Small" />
                </asp:TemplateField>
0
Comment
Question by:murbro
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 14

Accepted Solution

by:
CtrlAltDl earned 500 total points
ID: 40560805
You need a RowDataBound event.  It will call this event while it creates each row at that point you can rename buttons and or hide them.

    Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound
        ' Required to ignore the header and footer rows
        If e.Row.RowType = DataControlRowType.DataRow Then
                 'Check if it's Edit mode
                 If e.Row.RowState = DataControlRowState.Edit Then
                      'To access controls in a ItemTemplate
                      Dim gender= row.Field(Of String)("gender")
                      Dim Button8= DirectCast(e.Row.FindControl("Button8"), Button)

                       If gender = "Male" Then
                           Button8.Text = "Save Boy"
                       Else
                           Button8.Hide()
                       End If
                 End If
        End If
    End Sub

Open in new window


Disclaimer: My code may have some syntax errors, since I'm a C# dev.
0
 

Author Closing Comment

by:murbro
ID: 40561307
Thanks very much
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question