
Sucheta Patil
Top achievements
Rank 1
Sucheta Patil
asked on 11 Feb 2011, 03:37 PM
Hi
I am using RADGrid and have 7 fields to be entered to add a record by the user.
Voucher Date
Claim type
Claim Codes
Description
Amount
VAT
TotalAmount
I have a table, tblClaimType whose data I want to populate as drop down(RadComboBox) so that user can select from the dropdown.
All i want to know is how can I do this and also on selection of ClaimType I want to Populate tblExpCodes in Claimcodes drop down.
Can anyone advice me with examples of how to do this.
Thanks
Sucheta
I am using RADGrid and have 7 fields to be entered to add a record by the user.
Voucher Date
Claim type
Claim Codes
Description
Amount
VAT
TotalAmount
I have a table, tblClaimType whose data I want to populate as drop down(RadComboBox) so that user can select from the dropdown.
All i want to know is how can I do this and also on selection of ClaimType I want to Populate tblExpCodes in Claimcodes drop down.
Can anyone advice me with examples of how to do this.
Thanks
Sucheta
2 Answers, 1 is accepted
0

Sucheta Patil
Top achievements
Rank 1
answered on 11 Feb 2011, 06:31 PM
The below is my code
I get the error when i click 'Add new record'
Microsoft JScript runtime error: Sys.WebForms.PageRequestManagerServerErrorException: DataBinding: 'Telerik.Web.UI.GridInsertionObject' does not contain a property with the name 'Type'.
Please help me...
Thanks.
sucheta
protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e)
{
if (e.CommandName == RadGrid.InitInsertCommandName) //"Add new" button clicked
{
GridEditCommandColumn editColumn = (GridEditCommandColumn)RadGrid1.MasterTableView.GetColumn("EditCommandColumn");
editColumn.Visible = false;
}
else if (e.CommandName == RadGrid.RebindGridCommandName && e.Item.OwnerTableView.IsItemInserted)
{
e.Canceled = true;
System.Collections.Specialized.ListDictionary newValues = new System.Collections.Specialized.ListDictionary();
newValues["Type"] = "ChooseOne...";
newValues["ExpenditureCode"] = "ChooseOne...";
e.Item.OwnerTableView.InsertItem(newValues);
}
else
{
GridEditCommandColumn editColumn = (GridEditCommandColumn)RadGrid1.MasterTableView.GetColumn("EditCommandColumn");
if (!editColumn.Visible)
editColumn.Visible = true;
}
}
///////////////////////
<
telerik:RadGrid
ID
=
"RadGrid1"
GridLines
=
"None"
runat
=
"server"
AllowAutomaticDeletes
=
"True"
AllowAutomaticInserts
=
"True"
AllowAutomaticUpdates
=
"True"
AllowPaging
=
"True"
AutoGenerateColumns
=
"False"
DataSourceID
=
"LinqPettyCash"
OnItemUpdated
=
"RadGrid1_ItemUpdated"
OnItemDeleted
=
"RadGrid1_ItemDeleted"
OnItemInserted
=
"RadGrid1_ItemInserted"
OnDataBound
=
"RadGrid1_DataBound"
OnPreRender
=
"RadGrid1_PreRender"
OnItemCommand
=
"RadGrid1_ItemCommand"
>
<
PagerStyle
Mode
=
"NextPrevAndNumeric"
/>
<
MasterTableView
Width
=
"100%"
CommandItemDisplay
=
"Top"
DataKeyNames
=
"Id"
DataSourceID
=
"LinqPettyCash"
HorizontalAlign
=
"NotSet"
AutoGenerateColumns
=
"False"
>
<
Columns
>
<
telerik:GridEditCommandColumn
ButtonType
=
"ImageButton"
UniqueName
=
"EditCommandColumn"
>
<
ItemStyle
CssClass
=
"MyImageButton"
/>
</
telerik:GridEditCommandColumn
>
<
Telerik:GridBoundColumn
DataField
=
"VoucherDate"
ReadOnly
=
"true"
HeaderText
=
"VoucherDate"
SortExpression
=
"VoucherDate"
UniqueName
=
"VoucherDate"
DataType
=
"System.DateTime"
DataFormatString
=
"{0:dd/MM/yyyy}"
></
Telerik:GridBoundColumn
>
<
telerik:GridDropDownColumn
DataField
=
"Type"
DataSourceID
=
"LinqExpCodes"
HeaderText
=
"CodeType"
ListTextField
=
"Type"
ListValueField
=
"Type"
UniqueName
=
"CodeType"
ColumnEditorID
=
"GridDropDownColumnEditor1"
>
</
telerik:GridDropDownColumn
>
<%-- <
telerik:GridDropDownColumn
DataField
=
"ExpenditureCode"
DataSourceID
=
"LinqExpCodes"
HeaderText
=
"CodeDescrption"
ListTextField
=
"CodeDescrption"
ListValueField
=
"ExpenditureCode"
UniqueName
=
"CodeDescrption"
ColumnEditorID
=
"GridDropDownColumnEditor2"
>
</
telerik:GridDropDownColumn
>--%>
<
telerik:GridBoundColumn
DataField
=
"Description"
HeaderText
=
"ClaimDescription"
SortExpression
=
"Description"
UniqueName
=
"Description"
ColumnEditorID
=
"GridTextBoxColumnEditor1"
>
</
telerik:GridBoundColumn
>
<
telerik:GridTemplateColumn
HeaderText
=
"Amount"
SortExpression
=
"Amount"
UniqueName
=
"TemplateColumn"
EditFormColumnIndex
=
"1"
>
<
ItemTemplate
>
<
asp:Label
runat
=
"server"
ID
=
"lblAmount"
Text='<%# Eval("Amount", "{0:C}") %>'></
asp:Label
>
</
ItemTemplate
>
<
EditItemTemplate
>
<
span
><
telerik:RadNumericTextBox
runat
=
"server"
ID
=
"txtAmount"
Width
=
"40px"
DbValue='<%# Bind("Amount") %>'></
telerik:RadNumericTextBox
><
span
style
=
"color: Red"
><
asp:RequiredFieldValidator
ID
=
"RFV_txtAmount"
ControlToValidate
=
"txtAmount"
ErrorMessage
=
"*"
runat
=
"server"
>
</
asp:RequiredFieldValidator
></
span
>
</
EditItemTemplate
>
</
telerik:GridTemplateColumn
>
<
telerik:GridTemplateColumn
HeaderText
=
"VAT"
SortExpression
=
"VAT"
UniqueName
=
"TemplateColumn"
EditFormColumnIndex
=
"1"
>
<
ItemTemplate
>
<
asp:Label
runat
=
"server"
ID
=
"lblVAT"
Text='<%# Eval("VAT", "{0:C}") %>'></
asp:Label
>
</
ItemTemplate
>
<
EditItemTemplate
>
<
span
><
telerik:RadNumericTextBox
runat
=
"server"
ID
=
"txtVAT"
Width
=
"40px"
DbValue='<%# Bind("VAT") %>'></
telerik:RadNumericTextBox
><
span
style
=
"color: Red"
><
asp:RequiredFieldValidator
ID
=
"RFV_txtVAT"
ControlToValidate
=
"txtVAT"
ErrorMessage
=
"*"
runat
=
"server"
>
</
asp:RequiredFieldValidator
></
span
>
</
EditItemTemplate
>
</
telerik:GridTemplateColumn
>
<
telerik:GridTemplateColumn
HeaderText
=
"TotalAmount"
SortExpression
=
"TotalAmount"
UniqueName
=
"TemplateColumn"
EditFormColumnIndex
=
"1"
>
<
ItemTemplate
>
<
asp:Label
runat
=
"server"
ID
=
"lblAmount"
Text='<%# Eval("Amount", "{0:C}") %>'></
asp:Label
>
</
ItemTemplate
>
<
EditItemTemplate
>
<
span
><
telerik:RadNumericTextBox
runat
=
"server"
ID
=
"txtTotalAmount"
Width
=
"40px"
DbValue='<%# Bind("TotalAmnt") %>'></
telerik:RadNumericTextBox
><
span
style
=
"color: Red"
><
asp:RequiredFieldValidator
ID
=
"RFV_txtTotalAmount"
ControlToValidate
=
"txtTotalAmount"
ErrorMessage
=
"*"
runat
=
"server"
>
</
asp:RequiredFieldValidator
></
span
>
</
EditItemTemplate
>
</
telerik:GridTemplateColumn
>
<
telerik:GridButtonColumn
ConfirmText
=
"Delete this product?"
ConfirmDialogType
=
"RadWindow"
ConfirmTitle
=
"Delete"
ButtonType
=
"ImageButton"
CommandName
=
"Delete"
Text
=
"Delete"
UniqueName
=
"DeleteColumn"
>
<
ItemStyle
HorizontalAlign
=
"Center"
CssClass
=
"MyImageButton"
/>
</
telerik:GridButtonColumn
>
</
Columns
>
<
EditFormSettings
ColumnNumber
=
"2"
CaptionDataField
=
"Description"
CaptionFormatString
=
"Edit Claim Details {0}"
InsertCaption
=
"New Claim"
>
<
FormTableItemStyle
Wrap
=
"False"
></
FormTableItemStyle
>
<
FormCaptionStyle
CssClass
=
"EditFormHeader"
></
FormCaptionStyle
>
<
FormMainTableStyle
GridLines
=
"None"
CellSpacing
=
"0"
CellPadding
=
"3"
BackColor
=
"White"
Width
=
"100%"
/>
<
FormTableStyle
CellSpacing
=
"0"
CellPadding
=
"2"
Height
=
"110px"
BackColor
=
"White"
/>
<
FormTableAlternatingItemStyle
Wrap
=
"False"
></
FormTableAlternatingItemStyle
>
<
EditColumn
ButtonType
=
"ImageButton"
InsertText
=
"Insert Claim"
UpdateText
=
"Update claim"
UniqueName
=
"EditCommandColumn1"
CancelText
=
"Cancel edit"
>
</
EditColumn
>
<
FormTableButtonRowStyle
HorizontalAlign
=
"Right"
CssClass
=
"EditFormButtonRow"
></
FormTableButtonRowStyle
>
</
EditFormSettings
>
</
MasterTableView
>
<
ClientSettings
>
<
ClientEvents
OnRowDblClick
=
"RowDblClick"
/>
</
ClientSettings
>
</
telerik:RadGrid
>
0
Hello Sucheta,
You can use the built-in EmptyListItemText property to set an empty text to the control. This will also help you sidestep the aforementioned exception.
I hope this helps.
Regards,
Daniel
the Telerik team
You can use the built-in EmptyListItemText property to set an empty text to the control. This will also help you sidestep the aforementioned exception.
<
telerik:GridDropDownColumn
DataField
=
"Type"
DataSourceID
=
"LinqExpCodes"
HeaderText
=
"CodeType"
ListTextField
=
"Type"
ListValueField
=
"Type"
EmptyListItemText
=
"Choose one..."
EnableEmptyListItem
=
"true"
UniqueName
=
"CodeType"
ColumnEditorID
=
"GridDropDownColumnEditor1"
>
</
telerik:GridDropDownColumn
>
I hope this helps.
Regards,
Daniel
the Telerik team