Good Day,
I have an issue, I'm editing a rad grid when I click the edit button I able to edit the complete row (horizontal), but I want to see the edition fields in a vertical order. I attached a couple of pictures. I want so see it in vertical order.
Thanks in advance.
The Best.
William
I have an issue, I'm editing a rad grid when I click the edit button I able to edit the complete row (horizontal), but I want to see the edition fields in a vertical order. I attached a couple of pictures. I want so see it in vertical order.
Thanks in advance.
The Best.
William
<
telerik:RadGrid
runat
=
"server"
ID
=
"grid"
AutoGenerateColumns
=
"false"
AllowPaging
=
"true"
OnNeedDataSource
=
"grid_NeedDataSource"
OnUpdateCommand
=
"RadGrid1_UpdateCommand"
OnInsertCommand
=
"RadGrid1_InsertCommand"
OnItemCommand
=
"RadGrid1_ItemCommand"
onpageindexchanged
=
"grid_PageIndexChanged"
OnItemDataBound
=
"RadGrid1_ItemDataBound"
Culture
=
"es-CO"
>
<
MasterTableView
DataKeyNames
=
""
CommandItemDisplay
=
"Top"
InsertItemPageIndexAction
=
"ShowItemOnCurrentPage"
EditMode
=
"InPlace"
>
<
Columns
>
<
telerik:GridTemplateColumn
UniqueName
=
"CompanyID"
DataField
=
"CompanyID"
HeaderText
=
"Sociedad"
ForceExtractValue
=
"InEditMode"
ConvertEmptyStringToNull
=
"true"
>
<
EditItemTemplate
>
<
asp:DropDownList
CssClass
=
"dropdownlist"
ID
=
"ddlContainer"
runat
=
"server"
></
asp:DropDownList
>
</
EditItemTemplate
>
</
telerik:GridTemplateColumn
>
<
telerik:GridBoundColumn
DataField
=
"BranchID"
HeaderText
=
"Sucursal"
ForceExtractValue
=
"InEditMode"
ConvertEmptyStringToNull
=
"true"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"CenterCostID"
HeaderText
=
"Centro de Costo"
ForceExtractValue
=
"InEditMode"
ConvertEmptyStringToNull
=
"true"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"Descripcion"
HeaderText
=
"Descripcion"
ForceExtractValue
=
"InEditMode"
ConvertEmptyStringToNull
=
"true"
>
</
telerik:GridBoundColumn
>
<
telerik:GridTemplateColumn
UniqueName
=
"Active"
DataField
=
"Active"
HeaderText
=
"Activo"
>
<
ItemTemplate
>
<
asp:CheckBox
Checked='<%#Eval("Active") %>' ID="CheckBox1" runat="server" />
</
ItemTemplate
>
</
telerik:GridTemplateColumn
>
<
telerik:GridEditCommandColumn
ButtonType
=
"ImageButton"
/>
</
Columns
>
</
MasterTableView
>
<
PagerStyle
Mode
=
"NextPrevAndNumeric"
/>
</
telerik:RadGrid
>
6 Answers, 1 is accepted
0
Accepted
Princy
Top achievements
Rank 2
answered on 26 Oct 2010, 05:18 AM
Hello William,
In order to display the edit fields vertically, use EditMode property of MasterTableView as "EditForms" .
Thanks,
Princy.
In order to display the edit fields vertically, use EditMode property of MasterTableView as "EditForms" .
<
MasterTableView
DataKeyNames
=
""
CommandItemDisplay
=
"Top"
InsertItemPageIndexAction
=
"ShowItemOnCurrentPage"
EditMode
=
"EditForms"
>
Thanks,
Princy.
0
william
Top achievements
Rank 1
answered on 26 Oct 2010, 09:01 PM
Thanks a lot It works.
However I have found another additional issue implementing this.
I cannot hide a couple of columns since I have:
it's throwing the follow exception: Unable to cast object of type 'Telerik.Web.UI.GridEditFormItem' to type 'Telerik.Web.UI.GridHeaderItem'. And it is reasonable since e.Item is a GridEditFormItem.
I would appreciate if you can help me with this inconsistency.
Looking forward to your comments.
And I have an additional issue. I get the following exception when I'm trying to Insert a register: Cannot find cell bound to column with unique name 'Active'
It seems it doesn't found any GridBoundColumn any suggestion?
And finally the property
Kind Regards,
William
However I have found another additional issue implementing this.
I cannot hide a couple of columns since I have:
if
(!(e.Item
is
GridDataInsertItem) && e.Item.IsInEditMode)
{
//GridEditableItem editItem = (GridEditableItem)e.Item;
//TextBox txtid = (TextBox)editItem["CenterCostID"].Controls[0];
//txtid.ReadOnly = true;
GridEditFormItem item = (GridEditFormItem)e.Item;
CheckBox chkbx = (CheckBox)item[
"Active"
].FindControl(
"CheckBox1"
);
chkbx.Enabled =
true
;
GridHeaderItem header = (GridHeaderItem)e.Item;
header[
"CenterCostID"
].Visible =
false
;
item[
"CenterCostID"
].Visible =
false
;
item[
"Descripcion"
].Visible =
false
;
DropDownList dropDownList = (DropDownList)item[
"CompanyID"
].FindControl(
"ddlContainer"
);
dropDownList.DataSource = sp.GetSAPCenterCostBranchDDL();
dropDownList.SelectedValue = ((TextBox)item[
"CenterCostID"
].Controls[0]).Text +
" - "
+ ((TextBox)item[
"Descripcion"
].Controls[0]).Text;
dropDownList.DataBind();
}
it's throwing the follow exception: Unable to cast object of type 'Telerik.Web.UI.GridEditFormItem' to type 'Telerik.Web.UI.GridHeaderItem'. And it is reasonable since e.Item is a GridEditFormItem.
I would appreciate if you can help me with this inconsistency.
Looking forward to your comments.
And I have an additional issue. I get the following exception when I'm trying to Insert a register: Cannot find cell bound to column with unique name 'Active'
protected
void
RadGrid1_ItemDataBound(
object
sender, GridItemEventArgs e)
{
if
(e.Item.OwnerTableView.IsItemInserted && e.Item
is
GridDataInsertItem)
{
GridDataInsertItem insertItem = (GridDataInsertItem)e.Item;
TextBox txtid = (TextBox)insertItem[
"CenterCostID"
].Controls[0];
txtid.ReadOnly =
false
;
GridDataItem item = (GridDataItem)e.Item;
CheckBox chkbx = (CheckBox)item[
"Active"
].FindControl(
"CheckBox1"
);
chkbx.Enabled =
true
;
}
if
(!(e.Item
is
GridDataInsertItem) && e.Item.IsInEditMode)
{
GridEditFormItem editItem = (GridEditFormItem)e.Item;
TextBox txtid = (TextBox)editItem[
"CenterCostID"
].Controls[0];
txtid.ReadOnly =
true
;
//GridEditFormItem item = (GridEditFormItem)e.Item;
CheckBox chkbx = (CheckBox)editItem[
"Active"
].FindControl(
"CheckBox1"
);
chkbx.Enabled =
true
;
}
if
(e.Item
is
GridDataItem && !(!(e.Item
is
GridDataInsertItem) && e.Item.IsInEditMode) && !((e.Item.OwnerTableView.IsItemInserted && e.Item
is
GridDataInsertItem)))
{
GridDataItem item = (GridDataItem)e.Item;
CheckBox chkbx = (CheckBox)item[
"Active"
].FindControl(
"CheckBox1"
);
chkbx.Enabled =
false
;
}
}
<
telerik:RadGrid
runat
=
"server"
ID
=
"grid"
AutoGenerateColumns
=
"false"
AllowPaging
=
"true"
OnNeedDataSource
=
"grid_NeedDataSource"
OnUpdateCommand
=
"RadGrid1_UpdateCommand"
OnInsertCommand
=
"RadGrid1_InsertCommand"
OnItemCommand
=
"RadGrid1_ItemCommand"
OnItemDataBound
=
"RadGrid1_ItemDataBound"
Culture
=
"es-CO"
>
<
MasterTableView
DataKeyNames
=
"CenterCostID"
CommandItemDisplay
=
"Top"
InsertItemPageIndexAction
=
"ShowItemOnCurrentPage"
EditMode
=
"EditForms"
>
<
Columns
>
<
telerik:GridBoundColumn
DataField
=
"CenterCostID"
HeaderText
=
"Id Centro de Costo"
ForceExtractValue
=
"InEditMode"
ConvertEmptyStringToNull
=
"true"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"Description"
HeaderText
=
"Descripcion"
ForceExtractValue
=
"InEditMode"
ConvertEmptyStringToNull
=
"true"
>
</
telerik:GridBoundColumn
>
<
telerik:GridTemplateColumn
UniqueName
=
"Active"
DataField
=
"Active"
HeaderText
=
"Activo"
>
<
ItemTemplate
>
<
asp:CheckBox
Checked='<%#Eval("Active") %>' ID="CheckBox1" runat="server" />
</
ItemTemplate
>
</
telerik:GridTemplateColumn
>
<
telerik:GridEditCommandColumn
ButtonType
=
"ImageButton"
/>
</
Columns
>
</
MasterTableView
>
<
PagerStyle
Mode
=
"NextPrevAndNumeric"
/>
</
telerik:RadGrid
>
And finally the property
e.Item
is
GridDataInsertItem it seems always false which if you click insert or add it would never
execute the code inside if
(e.Item.OwnerTableView.IsItemInserted && e.Item
is
GridDataInsertItem)
Kind Regards,
William
0
Accepted
Princy
Top achievements
Rank 2
answered on 27 Oct 2010, 07:07 AM
Hello William,
Try the following code snippet in ItemDataBound event to hide grid column in edit mode. Since you are using EditMode as 'EditForms', check the item in edit mode as 'GridEditFormItem'.
C#:
Then for the second scenario, you have added the CheckBox inside ItemTemplate. So you cannot access it in insert mode. If you want the checkbox in insert/edit mode, add it in EditItemTemplate of GridTemplate column.
And in order to get the Item in insert mode(if EditMode is 'EditForms') , you need to use the following condition.
Hope this information helps,
Princy.
Try the following code snippet in ItemDataBound event to hide grid column in edit mode. Since you are using EditMode as 'EditForms', check the item in edit mode as 'GridEditFormItem'.
C#:
protected
void
grid_ItemDataBound(
object
sender, GridItemEventArgs e)
{
if
(e.Item
is
GridEditFormItem && e.Item.IsInEditMode)
//item about to edit
{
GridEditFormItem editItem = (GridEditFormItem)e.Item;
TextBox txt = (TextBox)editItem[
"CenterCostID"
].Controls[0];
txt.Parent.Parent.Visible =
false
;
}
}
Then for the second scenario, you have added the CheckBox inside ItemTemplate. So you cannot access it in insert mode. If you want the checkbox in insert/edit mode, add it in EditItemTemplate of GridTemplate column.
And in order to get the Item in insert mode(if EditMode is 'EditForms') , you need to use the following condition.
protected
void
grid_ItemDataBound(
object
sender, GridItemEventArgs e)
{
if
(e.Item.OwnerTableView.IsItemInserted && e.Item
is
GridEditFormInsertItem)
// item about to insert ( if EditMode is 'EditForms')
{
GridEditFormInsertItem insertItem = (GridEditFormInsertItem)e.Item;
. . . . . .
}
}
Hope this information helps,
Princy.
0
william
Top achievements
Rank 1
answered on 27 Oct 2010, 09:18 PM
Thanks a lot for your feedback. It has been very useful. However I have an additional issue.
Let's suppose first I bind a grid and I click on Add New Record option, afterwards I click on the Edit button (without to click on the previous Add New Record's CancelOption ) when I click on Edit option throws the following exception: System.InvalidCastException: Specified cast is not valid. And I'm not casting anything.
it doesn't happen if I try the opposite. (if I click on the edit button and after I click on add new record option ).
Any suggestion?
You can find this issue in the attached documents.
Thanks for your support.
William
Let's suppose first I bind a grid and I click on Add New Record option, afterwards I click on the Edit button (without to click on the previous Add New Record's CancelOption ) when I click on Edit option throws the following exception: System.InvalidCastException: Specified cast is not valid. And I'm not casting anything.
it doesn't happen if I try the opposite. (if I click on the edit button and after I click on add new record option ).
Any suggestion?
You can find this issue in the attached documents.
Thanks for your support.
William
0
Accepted
Princy
Top achievements
Rank 2
answered on 28 Oct 2010, 08:57 AM
Hello William,
One suggestion to eliminate this error is setting the Checked property of CheckBox in EditItemTemplate from code behind. Sample code is given below for you reference.
ASPX:
C#:
Thanks,
Princy.
One suggestion to eliminate this error is setting the Checked property of CheckBox in EditItemTemplate from code behind. Sample code is given below for you reference.
ASPX:
<telerik:GridTemplateColumn UniqueName=
"Active"
DataField=
"Active"
HeaderText=
"Activo"
>
<EditItemTemplate>
<asp:CheckBox ID=
"CheckBox1"
runat=
"server"
/>
</EditItemTemplate>
<ItemTemplate>
<asp:CheckBox ID=
"CheckBox1"
Checked=
'<%#Eval("Active") %>'
runat=
"server"
/>
</ItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridEditCommandColumn ButtonType=
"ImageButton"
/>
C#:
protected
void
grid_ItemDataBound(
object
sender, GridItemEventArgs e)
{
if
(e.Item
is
GridEditFormItem && e.Item.IsInEditMode && !e.Item.OwnerTableView.IsItemInserted)
//item about to edit
{
GridEditFormItem editItem = (GridEditFormItem)e.Item;
CheckBox chk = (CheckBox)editItem.FindControl(
"CheckBox1"
);
GridDataItem item = (GridDataItem)editItem.ParentItem;
CheckBox parentchk = (CheckBox)item.FindControl(
"CheckBox1"
);
if
(parentchk.Checked)
{
chk.Checked = parentchk.Checked; ;
}
}
}
Thanks,
Princy.
0
william
Top achievements
Rank 1
answered on 28 Oct 2010, 03:44 PM
Princy thanks a lot for your suggestion it was very useful.
All the Best,
William
All the Best,
William