Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 1.0 and 1.1 > ASP.NET 1.0 and 1.1 Professional
|
ASP.NET 1.0 and 1.1 Professional For advanced ASP.NET 1.x coders. Beginning-level questions will be redirected to other forums. NOT for "classic" ASP 3 or the newer ASP.NET 2.0 and 3.5
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Professional section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 20th, 2006, 06:40 PM
Registered User
 
Join Date: Mar 2006
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default How to change text on a ButtonColumn in a datagrid

Hi there,

I have a datagrid with a the end a ButtonColumn (linkbutton). The text on the button has to change between 2 names. When the situation = a then the text on the ButtonColumn has to be different then with situation b.

How can i change the text on the buttoncolumn in de code on runtime?

I looked in the Itemcreated event, but the buttoncolumn isnt an item...

Does anyone have a helpfull advise please?

Thanks in advance.

 
Old March 20th, 2006, 07:22 PM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Well if you are calling the datagrids databind() method you can do this:
   Private Sub dgItemBound(ByVal sender As Object, ByVal e As DataGridItemEventArgs) Handles [datagrid].ItemDataBound
        Dim lb As LinkButton
        If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Then
            lb = CType(e.Item.Cells([Cell control is in (0 based index)]).FindControl("[linkbutton Name]"), LinkButton)
            lb.Text = "text"
        End If

    End Sub

"The one language all programmers understand is profanity."
 
Old March 21st, 2006, 03:47 AM
Registered User
 
Join Date: Mar 2006
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

hi, thanks for the answer, but i still need some help here.

lb = CType(e.Item.Cells([Cell control is in (0 based index)]).FindControl("[linkbutton Name]"), LinkButton)

i use c# and here is where im stuck. i cant seem to get this ctype or in c# Convert.ChangeType to work. You use Linkbutton at the end, but i dont kwno what to place here, it just nags about that i dont use the right type here.

also i want to know what/why do u use cells[] here? my column with the linkbutton is in column 8.

also i dont know what the name is of the linkbutton, i cant set a name of do u mean the text on the button perhaps?

i hope someone can help me.

thanks!

 
Old March 21st, 2006, 09:03 AM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Fidelio,
  I am not sure what the C# equivelant is for that line of code, play around with it and im sure that you will figure it out. Also your post was very vague in that you didn't specifiy if you were auto generating columns, buidling the datagrid on the fly, etc.

I use the above code in conjuntion with a Datagrid whos AutoGenerateColumns value is false then I have a Datagrid <columns></columns> collection. Inside of those columns i have something like this:
    <asp:TemplateColumn>
           <ItemTemplate>
        <asp:LinkButton CommandName="Edit" Text="Edit" CausesValidation="false" runat="server" ID="Linkbutton1" />
            <asp:LinkButton CommandName="Delete" CausesValidation="False" Text="Delete" runat="server" ID="lbDelete" />
       </ItemTemplate>
       <EditItemTemplate>
        <asp:LinkButton CommandName="Cancel" CausesValidation="False" Text="Cancel" runat="server" />
        <asp:LinkButton CommandName="Update" CausesValidation="True" Text="Update" runat="server" />
      </EditItemTemplate>
    </asp:TemplateColumn>
The 2 link buttons in the EditItemTemplate are hidden until the datagrid 'Edit' Command is called the first 2 link buttons appear as the first cell in every row and are visible when the Databind() method is called on the datagrid and if you look, i have named that link button so my code would look like this:
        lb = CType(e.Item.Cells(0).FindControl("lbDelete"), LinkButton)

As far as your question about why do I use cells, that is how you manipulate controls or text inside of a datagrid, you have to select the cell and then the control you want to work with (or the text in the cell if there is no control). As far as the why for this? Ask Microsoft. Hope this helps.

"The one language all programmers understand is profanity."
 
Old March 21st, 2006, 05:51 PM
Registered User
 
Join Date: Mar 2006
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

hello,

thanks for your very helpfull answers. sorry for that i wasnt very accurate in my problem description.

i already got the solution by using a template column in the datagrid. then i could use the findcontrol() function.

thanks for the help and efforts.

Frederik






Similar Threads
Thread Thread Starter Forum Replies Last Post
Need to change color of text in a text box? larry HTML Code Clinic 6 December 29th, 2006 05:14 AM
to change the text format vubinhsg BOOK: Access 2003 VBA Programmer's Reference 1 December 30th, 2004 09:46 AM
Edit/Delete ButtonColumn not working planoie ASP.NET 1.0 and 1.1 Professional 9 August 30th, 2004 07:39 AM
buttonColumn and target=_blank collie VB.NET 2002/2003 Basics 2 March 15th, 2004 05:26 AM
Datagrid ButtonColumn collie VB.NET 2002/2003 Basics 7 January 19th, 2004 09:38 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.