Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to set UpdateText programmatically 1

Status
Not open for further replies.

RandyBlackburn

Programmer
Oct 1, 2002
153
US
My "new" button adds a blank record to the top of my asp.net 1.1 datagrid. To complete the transaction the user currently hits the "update" command column.

I would prefer that the column be titled "Add". So I need to change the UpdateText property of the editcommandcolumn from "Update" to "Add".

I see examples of asp code, but I don't know how to change it dynamically.

Any help will be appreciated.

Randy

 
Go into the property builder and click on the column, there you can change the text of the buttons.
 
Jim,

What I want to do is change it programmatically.... usually it will say "update", but when adding it will say "add
 
Use the OnItemDataBound and do this

if adding then
e.Item.Cell[0].Text = "Add" (or whatever cell your button is in)
 
ItemDataBoundEvent:
Code:
If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType  
                      = ListItemType.AlternatingItem Then

   Dim lb As New LinkButton
   lb = e.Item.Cells(<cell index>).Controls(0)
   lb.Text = "Add"
End if
 
will this do what u need?
Code:
Sub AddNew(sender As Object, e As EventArgs)
   'adding new action code here, then
    Dim myBtn As EditCommandColumn = CType(dgRef.Columns(0), EditCommandColumn)
    myBtn.UpdateText = "Add"
End Sub

    Sub DataGrid_Edit(ByVal Sender As Object, ByVal E As DataGridCommandEventArgs)
        If Not isEditing Then
            dgRef.EditItemIndex = e.Item.ItemIndex
            Dim myBtn As EditCommandColumn = CType(dgRef.Columns(0), EditCommandColumn)
            myBtn.UpdateText = "Update"
            BindGrid()
            BindVenDDL()
        End If
    End Sub
 
I want to chenge the title of the link button on the generated editcommand column.

If done in asp script, it would appear as:

<Columns>

<asp:EditCommandColumn
EditText="Edit"
CancelText="Cancel"
UpdateText="Update"
HeaderText="Edit item">

<ItemStyle Wrap="False">
</ItemStyle>

<HeaderStyle Wrap="False">
</HeaderStyle>

</asp:EditCommandColumn>
 

These last recommendations look like they address the problem... I'll implement asap, and let you know

Thanks,
Randy
 

Great support "guys!"

This was simpler than I expected.

I ended up using Jbenson's recommendation, mostly because it was somewhat less code, and it worked.

Adamroof's solution looked to address the issue more direclty, but was a bit more complex.

My implementation is below:

Code:
Private Sub LeadGrid_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles LeadGrid.ItemDataBound
        If NewLeadBtn.Visible = False Then
            If e.Item.ItemType = ListItemType.EditItem Then
                Dim lb As New LinkButton
                lb = e.Item.Cells(7).Controls(0)
                lb.Text = "Add"
            End If
        End If
    End Sub
 
glad u got it working, but more complex?????

Dim myBtn As EditCommandColumn = CType(dgRef.Columns(0), EditCommandColumn)
myBtn.UpdateText = "Add"

is all it is, and uses your existing add new and edit code already.

anyway, again, glad its working.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top