Solved

ASP.net Change button text for each line of GridView

Posted on 2015-01-20
2
364 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
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Any Third party toll for Integrating chat system on ASP.NET ? 2 34
ASP.NET Core index.html  LOCALHOST page cannot be found 2 25
SQL Login 17 41
Help with LINQ and XML 10 28
Microsoft Reports are based on a report definition, which is an XML file that describes data and layout for the report, with a different extension. You can create a client-side report definition language (*.rdlc) file with Visual Studio, and build g…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

863 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now