This is a migrated thread and some comments may be shown as answers.

RadGrid - after postback textbox field is empty in the code behind

1 Answer 475 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Walt
Top achievements
Rank 1
Walt asked on 06 Jun 2016, 08:53 PM

Hi,

I am using a RadGrid to show data (obviously).  Within a specific cell I have a literal that is called "DocumentName".  The user has an option to rename that generic name to something custom.  What I do is have a button that they click and an asp:TextBox control becomes visible with a save button.  When I enter text into that textbox and hit the save button I want to get that new value from the textbox.  However, I am getting an empty string every time. I have tried multiple ways  Here is my code.

foreach (GridDataItem g in EventsDocsRadGV.Items)
{

// First way - returns an empty string
TextBox RenameDocumentName = (TextBox)g.FindControl("RenameDocumentName");

// Second way - returns an empty string
string txt = (g["EventTypeDesc"].FindControl("RenameDocumentName") as TextBox).Text;

// Third way - returns an empty string
GridDataItem item = (GridDataItem)g;
TextBox RenameDocumentName2 = (TextBox)item["EventTypeDesc"].FindControl("RenameDocumentName");

}

I also tried the same only wrapped in this loop
foreach (GridDataItem g in EventsDocsRadGV.MasterTableView.Items)
{

// First way - returns an empty string
TextBox RenameDocumentName = (TextBox)g.FindControl("RenameDocumentName");

// Second way - returns an empty string
string txt = (g["EventTypeDesc"].FindControl("RenameDocumentName") as TextBox).Text;
// Third way - returns an empty string
GridDataItem item = (GridDataItem)g;
TextBox RenameDocumentName2 = (TextBox)item["EventTypeDesc"].FindControl("RenameDocumentName");

}

I can access the other properties and cells that were bound onitemdatabound but not this textbox.  Ideas?

Thanks!

1 Answer, 1 is accepted

Sort by
0
Viktor Tachev
Telerik team
answered on 08 Jun 2016, 12:18 PM
Hi Walt,

Please examine the article below that illustrates how to access the controls inside grid cells in various scenarios.


With that said, would you elaborate in more detail on what is your exact scenario? Where are the Button, Literal and TextBox controls placed? Are they inside the grid or outside? What event are you using to access the controls and change the text for the Literal?

Also, why do you need to implement that behavior? Having better understanding of your goal will enable us to provide more to-the-point suggestions on how to implement it.

Regards,
Viktor Tachev
Telerik
Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
Tags
Grid
Asked by
Walt
Top achievements
Rank 1
Answers by
Viktor Tachev
Telerik team
Share this question
or