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

[Solved] Getting grid item value when editing inlline

3 Answers 137 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Steve Hochreiter
Top achievements
Rank 1
Steve Hochreiter asked on 25 Jun 2008, 09:59 PM
I'm using the following code to retrieve a value from a grid column and it keeps returning the "&nbsp ;" instead of the value in the column.  I've used this code before with the Q3 2007 version so I don't know if it will work for the AJAX version.  The dropdown is created and is loaded properly.  All I need to do is set the dropdown selected value to what is in the record.  The column "TimeCodeID" is Display=false.  I've tried Display=true with the same problem. Any idea what I can do to get the value of the column?  Thank you.

<

telerik:GridBoundColumn DataField="TimeCodeID" HeaderText="Time Code ID" UniqueName="TimeCodeID" DataType="System.Int32" Display="False">

</telerik:GridBoundColumn>



protected

void RadGridEdit_ItemCreated(object sender, Telerik.Web.UI.GridItemEventArgs e)

{

if ((e.Item is GridEditableItem) && (e.Item.IsInEditMode))

{

GridEditableItem editItem = e.Item as GridEditableItem;

DropDownList ddlTimeCode = (DropDownList)editItem["TimeCode"].FindControl("ddlTimeCode");

ddlTimeCode.Items.Clear();
ddlTimeCode.DataSource =
tblTimeCode.GetCache(DBConnection);
ddlTimeCode.DataTextField =
"TimeCode";
ddlTimeCode.DataValueField =
"ID";
ddlTimeCode.DataBind();

if (e.Item.OwnerTableView.IsItemInserted)

{

}

else

{

GridEditableItem myItem = e.Item as GridEditableItem;

//This line returns &nbsp instead of the value in the column
string strTimeCodeID = myItem["TimeCodeID"].Text;

//set dropdown to show what was selected

ddlTimeCode.SelectedValue = strTimeCodeID;

}

}

3 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 26 Jun 2008, 05:33 AM
Hi Steve,

Try accessing it as GridDataItem as shown below.

CS:
   else if (e.Item is GridDataItem) 
        { 
            GridDataItem myItem = (GridDataItem)e.Item; 
            string strTimeCodeID = myItem["TimeCodeID"].Text.ToString(); 
        } 

Thanks
Shinu.
0
Steve Hochreiter
Top achievements
Rank 1
answered on 26 Jun 2008, 01:46 PM
Well, it still returns &nbsp for the value using the new code.  This is executing in the ItemCreated section.  Anymore ideas?  Thank you.
0
Shinu
Top achievements
Rank 2
answered on 27 Jun 2008, 07:38 AM
Hi Steve,

Set the "TimeCodeID" field as the DataKeyName and try accessing it as shown below.

CS:
 else if (e.Item is GridDataItem)  
        {  
            GridDataItem myItem = (GridDataItem)e.Item;  
            string strTimeCodeID =myItem.GetDataKeyValue("TimeCodeID").ToString();  
        }  


Thanks
Shinu.
Tags
Grid
Asked by
Steve Hochreiter
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Steve Hochreiter
Top achievements
Rank 1
Share this question
or