I have a radgrid and a textbox where I would like to show the value of a column when the record is in edit mode. The value I would like to get is contained in a readonly column and it is listed in DataKeyNames, it is basically the transaction id given by the SQL database when the item is created.
<MasterTableView CommandItemDisplay="TopAndBottom" DataSourceID="SqlDataSource1" AutoGenerateColumns="False" DataKeyNames="TransazioneID" AllowFilteringByColumn="True">
I cannot get it out.
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
if (e.Item is GridEditableItem && e.Item.IsInEditMode)
{
GridEditableItem item = e.Item as GridEditableItem;
string str = item["TransazioneID"].Text;
TextBox1.Text = str;
The code doesn't give me errors but shows nothing. How can I get the value of "TransactionID" for the record in edit mode?
Try the following code to get the datakey value in edit mode.
protected void rdg_ItemDataBound(object sender, GridItemEventArgs e)
{
if (e.Item is GridEditableItem && e.Item.IsInEditMode)
{
GridEditableItem editedItem = e.Item as GridEditableItem;
string str = editedItem.GetDataKeyValue("TransazioneID").ToString();
TextBox1.Text = str ;
}
}
Try this code ,
GridEditableItem editedItem = e.Item as GridEditableItem;
int tID = Int32.Parse(editedItem.OwnerTableView.DataKeyValues[editedItem.ItemIndex]["TransazioneID"].ToString());
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.