?
Solved

ASP.net Change button text for each line of GridView

Posted on 2015-01-20
2
Medium Priority
?
403 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:Murray Brown
[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 2000 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:Murray Brown
ID: 40561307
Thanks very much
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses
Course of the Month12 days, 5 hours left to enroll

752 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