Hi,
I have a combination key made up by 3 fields (lead_id,location_id,seq_id). I need to increment seq_id in my code-behind before inserting into the table while the first 2 keys stay the same. Similar to this post but I'm doing in-place editing:
http://www.telerik.com/forums/add-edit-with-user-defined-primary-key
I'm unsure if it's doable but I tried both in-place and GridTemplateColumn as suggested in the post, but couldn't get it to work. I received this error - "Exception has been thrown by the target of an invocation." after it leaves the InsertCommand event. Is there anything I'm missing to get the seq_id modify and insert to table? I did set ReadOnly="False".
Here's my ascx:
Here's my code-behind:
Thank you in advance for your help.
Helen
I have a combination key made up by 3 fields (lead_id,location_id,seq_id). I need to increment seq_id in my code-behind before inserting into the table while the first 2 keys stay the same. Similar to this post but I'm doing in-place editing:
http://www.telerik.com/forums/add-edit-with-user-defined-primary-key
I'm unsure if it's doable but I tried both in-place and GridTemplateColumn as suggested in the post, but couldn't get it to work. I received this error - "Exception has been thrown by the target of an invocation." after it leaves the InsertCommand event. Is there anything I'm missing to get the seq_id modify and insert to table? I did set ReadOnly="False".
Here's my ascx:
<
telerik:RadGrid
ID
=
"RadGrid1"
runat
=
"server"
MasterTableView-EditMode
=
"InPlace"
DataSourceID
=
"ObjectDataSource1"
OnInsertCommand
=
"RadGrid1_InsertCommand"
AllowAutomaticDeletes
=
"True"
AllowAutomaticInserts
=
"True"
AllowAutomaticUpdates
=
"True"
AutoGenerateDeleteColumn
=
"True"
AutoGenerateEditColumn
=
"True"
>
<
MasterTableView
AllowAutomaticDeletes
=
"False"
AllowAutomaticInserts
=
"True"
AllowAutomaticUpdates
=
"True"
AutoGenerateColumns
=
"False"
CommandItemDisplay
=
"Top"
DataKeyNames
=
"lead_id,location_id,seq_id"
DataSourceID
=
"ObjectDataSource1"
>
<
NoRecordsTemplate
>
No Record Exists</
NoRecordsTemplate
>
<
Columns
>
<
telerik:GridBoundColumn
DataField
=
"lead_id"
DataType
=
"System.Int32"
FilterControlAltText
=
"Filter lead_id column"
HeaderText
=
"lead_id"
ReadOnly
=
"True"
SortExpression
=
"lead_id"
UniqueName
=
"lead_id"
Visible
=
"False"
>
<
ColumnValidationSettings
>
<
ModelErrorMessage
Text
=
""
/>
</
ColumnValidationSettings
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"location_id"
DataType
=
"System.Int32"
FilterControlAltText
=
"Filter location_id column"
HeaderText
=
"location_id"
ReadOnly
=
"True"
SortExpression
=
"location_id"
UniqueName
=
"location_id"
Visible
=
"False"
>
<
ColumnValidationSettings
>
<
ModelErrorMessage
Text
=
""
/>
</
ColumnValidationSettings
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"seq_id"
DataType
=
"System.Int32"
FilterControlAltText
=
"Filter seq_id column"
HeaderText
=
"seq_id"
ReadOnly
=
"False"
SortExpression
=
"seq_id"
UniqueName
=
"seq_id"
>
<
ColumnValidationSettings
>
<
ModelErrorMessage
Text
=
""
/>
</
ColumnValidationSettings
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"current_provider"
FilterControlAltText
=
"Filter current_provider column"
HeaderText
=
"current_provider"
SortExpression
=
"current_provider"
UniqueName
=
"current_provider"
>
<
ColumnValidationSettings
>
<
ModelErrorMessage
Text
=
""
/>
</
ColumnValidationSettings
>
</
telerik:GridBoundColumn
>
</
Columns
>
</
MasterTableView
>
</
telerik:RadGrid
>
<
asp:ObjectDataSource
ID
=
"ObjectDataSource1"
runat
=
"server"
DeleteMethod
=
"Delete"
InsertMethod
=
"Insert"
OldValuesParameterFormatString
=
"original_{0}"
SelectMethod
=
"GetData"
TypeName
=
"SALTDetailProviderDALTableAdapters.salt_company_providerTableAdapter"
UpdateMethod
=
"Update"
>
<
DeleteParameters
>
<
asp:Parameter
Name
=
"Original_lead_id"
Type
=
"Int32"
/>
<
asp:Parameter
Name
=
"Original_location_id"
Type
=
"Int32"
/>
<
asp:Parameter
Name
=
"Original_seq_id"
Type
=
"Int32"
/>
</
DeleteParameters
>
<
InsertParameters
>
<
asp:Parameter
Name
=
"lead_id"
Type
=
"Int32"
/>
<
asp:Parameter
Name
=
"location_id"
Type
=
"Int32"
/>
<
asp:Parameter
Name
=
"seq_id"
Type
=
"Int32"
/>
<
asp:Parameter
Name
=
"current_provider"
Type
=
"String"
/>
<
asp:Parameter
Name
=
"contract_exp_dt"
Type
=
"DateTime"
/>
<
asp:Parameter
Name
=
"data_type"
Type
=
"Int16"
/>
<
asp:Parameter
Name
=
"ld_min"
Type
=
"Int32"
/>
<
asp:Parameter
Name
=
"line_cnt"
Type
=
"Int32"
/>
<
asp:Parameter
Name
=
"primary_yn"
Type
=
"String"
/>
</
InsertParameters
>
<
SelectParameters
>
<
asp:ControlParameter
ControlID
=
"LeadIdLabel"
Name
=
"lead_id"
PropertyName
=
"Text"
Type
=
"Int32"
/>
</
SelectParameters
>
<
UpdateParameters
>
<
asp:Parameter
Name
=
"current_provider"
Type
=
"String"
/>
<
asp:Parameter
Name
=
"contract_exp_dt"
Type
=
"DateTime"
/>
<
asp:Parameter
Name
=
"data_type"
Type
=
"Int16"
/>
<
asp:Parameter
Name
=
"ld_min"
Type
=
"Int32"
/>
<
asp:Parameter
Name
=
"line_cnt"
Type
=
"Int32"
/>
<
asp:Parameter
Name
=
"primary_yn"
Type
=
"String"
/>
<
asp:Parameter
Name
=
"Original_lead_id"
Type
=
"Int32"
/>
<
asp:Parameter
Name
=
"Original_location_id"
Type
=
"Int32"
/>
<
asp:Parameter
Name
=
"Original_seq_id"
Type
=
"Int32"
/>
</
UpdateParameters
>
</
asp:ObjectDataSource
>
Here's my code-behind:
protected
void
RadGrid1_InsertCommand(
object
sender, GridCommandEventArgs e)
{
// Get last item's
int
count = RadGrid1.Items.Count;
GridDataItem item = RadGrid1.Items[count - 1]
as
GridDataItem;
// Get last item's provider name
string
providerName = item[
"current_provider"
].Text;
// Add 1 to last item's seq id
string
strSeqid = item[
"seq_id"
].Text;
int
seqid =
int
.Parse(item[
"seq_id"
].Text) + 1;
// item about to get inserted
GridDataInsertItem insertedItem = (GridDataInsertItem)e.Item;
// Get provider name of the item about to get inserted
TextBox providerNameTextBox = insertedItem[
"current_provider"
].Controls[0]
as
TextBox;
string
providerNameInserted = providerNameTextBox.Text;
// Modify the seq id
(insertedItem[
"seq_id"
].Controls[0]
as
TextBox).Text = seqid.ToString().Trim();
}
Thank you in advance for your help.
Helen