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

Assign unbound grid edit form textbox values

1 Answer 101 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Christian
Top achievements
Rank 1
Christian asked on 03 Jan 2012, 04:11 PM
Hi,

I have a grid that consists of customer details which is populated from a database. One of the customer attributes is the Sort Code. I would like to be able to bind the values of this to the appropriate textboxes when editing a customer. In the database, this item is stored as a single 6 digit code, however, as is convention, the user enters the code in 3, 2 digit text boxes. Usually one uses the

Text='<%# Bind("blah"%>'
 technique, however in this instance this is not possible as there are 3 separate textboxes. When would be the best point to assign the values through codebehind? At the editcommand event (though afaik edit form items are not accessible from here)? Any help would be greatly appreciated.

Cheers,
Christian

1 Answer, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 2
answered on 04 Jan 2012, 06:31 AM
Hello,

Try the following code.
C#:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
 if (e.Item is GridEditableItem && e.Item.IsInEditMode)
 {
   GridEditableItem item = (GridEditableItem)e.Item;
   TextBox txt = (TextBox)item.FindControl("TextBox1");
   txt.Text = "your text";
 }
}

Thanks,
Princy.
Tags
Grid
Asked by
Christian
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Share this question
or