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

[Solved] set value of hidden column

1 Answer 161 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Adam Hager
Top achievements
Rank 1
Adam Hager asked on 10 Nov 2009, 10:21 PM
I have the latest version of the rad grid and have it bound to the EntityDataSource control.  I have a field that I need to hide in all modes.  My trouble is that in insert mode because it is hidden my code to set the default value in the ItemCommand event is not working.  The dictionary is getting populated correctly however when I insert I am getting a foreign key contraint error due to the fact that the hidden field is not getting populated.  Is there a way around this?  I can even leave the field on the screen in edit mode as long as I can make it read only.  When I set the readonly property, the field was not visible but again the value I need was not set.

<

 

telerik:RadGrid runat="server" ID="RadGrid2" AllowPaging="True"

 

 

AllowSorting="True" Width="97%" DataSourceID="EntityDataSource1" AllowAutomaticInserts="True"

 

 

AllowAutomaticUpdates="True" AllowAutomaticDeletes="False" ShowStatusBar="True"

 

 

GridLines="None" AutoGenerateEditColumn="True"

 

 

AutoGenerateColumns="False" OnItemCommand="RadGrid2_ItemCommand">

 

 

<PagerStyle Mode="NumericPages" AlwaysVisible="true" />

 

 

<MasterTableView Width="100%" CommandItemDisplay="Top"

 

 

DataSourceID="EntityDataSource1"

 

 

DataKeyNames="VendorCrewId">

 

 

<Columns>

 

 

<telerik:GridBoundColumn DataField="FirstName" HeaderText="FirstName"

 

 

SortExpression="FirstName" UniqueName="FirstName">

 

 

</telerik:GridBoundColumn>

 

 

<telerik:GridBoundColumn DataField="LastName" HeaderText="LastName" SortExpression="LastName"

 

 

UniqueName="LastName">

 

 

</telerik:GridBoundColumn>

 

 

<telerik:GridBoundColumn DataField="Bio" HeaderText="Bio"

 

 

SortExpression="Bio" UniqueName="Bio" ItemStyle-Width="300px" ItemStyle-HorizontalAlign="NotSet">

 

 

</telerik:GridBoundColumn>

 

 

<telerik:GridCheckBoxColumn DataField="IsActive" DataType="System.Boolean"

 

 

HeaderText="IsActive" SortExpression="IsActive" UniqueName="IsActive">

 

 

</telerik:GridCheckBoxColumn>

 

 

<telerik:GridBinaryImageColumn DataField="Image" HeaderText="Image" UniqueName="Upload" ImageAlign="NotSet"

 

 

ImageHeight="80px" ImageWidth="80px" ResizeMode="Fit"

 

 

DataAlternateTextFormatString="Image of {0}">

 

 

<HeaderStyle Width="10%" />

 

 

</telerik:GridBinaryImageColumn>

 

 

<telerik:GridBoundColumn DataField="VendorCrewId" DataType="System.Int32"

 

 

HeaderText="VendorCrewId" ReadOnly="True" Visible="False" SortExpression="VendorCrewId"

 

 

UniqueName="VendorCrewId">

 

 

</telerik:GridBoundColumn>

 

 

<telerik:GridBoundColumn DataField="CompanyEntities.CompanyEntityId"

 

 

DataType="System.Int32" HeaderText="Vendor Id"

 

 

SortExpression="CompanyEntities.CompanyEntityId"

 

 

Visible="False">

 

 

</telerik:GridBoundColumn>

 

 

</Columns>

 

 

<EditFormSettings EditFormType="AutoGenerated">

 

 

<EditColumn ButtonType="ImageButton" />

 

 

</EditFormSettings>

 

 

</MasterTableView>

 

 

</telerik:RadGrid>

 



 

protected void RadGrid2_ItemCommand(object source, GridCommandEventArgs e)

 

{

 

if (e.CommandName == RadGrid.InitInsertCommandName) //"Add new" button clicked

 

{

e.Canceled =

true;

 

 

//Prepare an IDictionary with the predefined values

 

System.Collections.Specialized.

ListDictionary newValues = new System.Collections.Specialized.ListDictionary();

 

newValues[

"CompanyEntities.CompanyEntityId"] = Page.Request.QueryString["1"];

 

newValues[

"IsActive"] = true;

 

 

//Insert the item and rebind

 

e.Item.OwnerTableView.InsertItem(newValues);

}

}

1 Answer, 1 is accepted

Sort by
0
Tsvetoslav
Telerik team
answered on 13 Nov 2009, 09:33 AM
Hi Adam,

You can attach an event handler to the EntityDataSource's OnInserting event and add your default value there using the incoming EntityDataSourceChangingEventArgs object.

I hope this helps.

Regards,
Tsvetoslav
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
Grid
Asked by
Adam Hager
Top achievements
Rank 1
Answers by
Tsvetoslav
Telerik team
Share this question
or