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

Binding text box in radgrid

2 Answers 326 Views
Grid
This is a migrated thread and some comments may be shown as answers.
RB
Top achievements
Rank 1
RB asked on 16 Jun 2014, 05:22 PM
I have a radgrid in which the last column is a text box. I have added the text box through a GridTemplateColumn.
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;
 The TextBoxTemplate is as follows:
   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!

2 Answers, 1 is accepted

Sort by
0
Konstantin Dikov
Telerik team
answered on 19 Jun 2014, 01:39 PM
Hello,

Could you please elaborate what edit mode you are using, how do you bind your grid and how you are updating the values in your database.

Additionally, providing the entire markup and code-behind of your RadGrid settings will help us get a better idea of your exact scenario and give a relevant to your project suggestions.

On a side note, please note that you need to have EditItemTemplate and InsertItemTemplate for the GridTemplateColumn, in order to take advantage of the built-in editing functionality of RadGrid.

I am looking forward to your reply.


Regards,
Konstantin Dikov
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
RB
Top achievements
Rank 1
answered on 19 Jun 2014, 05:40 PM
The NeedDataSource event was not being fired after Rebind is called. So had to set Grid.DataSource to null, before calling the Rebind method. It worked!
Tags
Grid
Asked by
RB
Top achievements
Rank 1
Answers by
Konstantin Dikov
Telerik team
RB
Top achievements
Rank 1
Share this question
or