I have a radgrid in which the last column is a text box. I have added the text box through a GridTemplateColumn.
The TextBoxTemplate is as follows:
This works fine when the grid is loaded for the first time. But when the text in the text box is changed and the "Save" button is clicked, instead of showing the new value it displays the previous one.
I checked that the value in the DB is not saved till the whole process ends. Hence the code :((DataRowView)container.DataItem)[this._columnName].ToString(), gets the value from the DB which is the old value. After the process finishes, the db gets the new value.
For example, when the grid loads for the first time, the Billing number is displayed as 90. If I change it to 91, it again displays 90 instead of 91!
templateColumn = new GridTemplateColumn();
templateColumnName = "Billing Number"
this._RadGrid1.MasterTableView.Columns.Add(templateColumn);
templateColumn.ItemTemplate = new TextBoxTemplate(templateColumnName);
templateColumn.HeaderText = templateColumnName;;
templateColumn.DataField = templateColumnName;
templateColumn.AllowFiltering = false;
public class TextBoxTemplate : ITemplate
{
protected RadTextBox _textBox;
string _columnName;
public TextBoxTemplate(string columnName)
{
this._columnName = columnName;
}
public void InstantiateIn(System.Web.UI.Control container)
{
this._textBox = new RadTextBox();
this._textBox.ID = this._columnName;
container.Controls.Add(this._textBox);
this._textBox.DataBinding += new EventHandler(_textBox_DataBinding);
}
void _textBox_DataBinding(object sender, EventArgs e)
{
RadTextBox txt = (RadTextBox)sender;
GridDataItem container = (GridDataItem)txt.NamingContainer;
txt.Text = ((DataRowView)container.DataItem)[this._columnName].ToString();
}
}
This works fine when the grid is loaded for the first time. But when the text in the text box is changed and the "Save" button is clicked, instead of showing the new value it displays the previous one.
I checked that the value in the DB is not saved till the whole process ends. Hence the code :((DataRowView)container.DataItem)[this._columnName].ToString(), gets the value from the DB which is the old value. After the process finishes, the db gets the new value.
For example, when the grid loads for the first time, the Billing number is displayed as 90. If I change it to 91, it again displays 90 instead of 91!