NewText is not working

KaranGupta
KaranGupta used Ask the Experts™
on
Hi

I have a grid view in which I have a commandfield (please check the code section)

My requirement is when I add a new record in the grid the text should be add and when I update the existing row the text should be update. I have tried to use NewText as well. But I am not able to get the desired result.

Am I missing something.

Kindly advice

Regards
Karan Gupta
<asp:CommandField HeaderText = "Edit" EditText = "Edit" CancelText = "Cancel" ShowEditButton = "true" UpdateText = "Update" ControlStyle-CssClass = "LinkButton"/>

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Author

Commented:
Hi

I am not getting the information I need. Could you please tell me where is it.

Regards
Karan Gupta
Hi Karan,
You can not do what you want with CommandField.
CommandField is only for Edit/Delete/Update/Cancel.

For adding new record you can add another button.

Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

Author

Commented:
Hi

I think I was not able to elaborate the question well. I don't want functionality but what I want is when the user adds new record in the gridview then text of update Link should be "Add" and if updating the existing record then it should be "update". Please let me know in case of any other information.

Regards
Karan Gupta

Commented:
The GridView does not have feature to add records using New button. You need to use DetailsView to have a form to add records and display it in GridView.
If you want to display 'New' button, you need to use CommandField.ShowInsertButton Property.  But this property applies only to data-bound controls that support insert operations, such as the DetailsView control.
Try the following examples
Detailsview: insert / update single record
http://www.devx.com/dotnet/Article/22141/0/page/4
Inserting new row in GridView in ASP.NET 2.0
GridView extras - DetailsView

Author

Commented:
Hi

I just want to rename update button at run time. Is that possible.

Regards
Karan
try at OnRowDataBound event, access that button / link and assign new text value.

Author

Commented:
How can we access that
For that you have to manually add template field and add linkbutton. you can not access command field directly.
Hope this helps you.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial