I am using Radgrid for my applicaiton. I have added three Rad Buttons to "CommandItemTemplate" That are add button, edit button and delete button. When I click add button, it is always inserting a new row in grid. I dont want that. I wanted to enable my own panel. How to disable this new row insertion.
Also when I am clicking the edit button, it is opening the respective row in edit mode. How to disable this feature. I wanted to enable my own panel, when I click the edit button. Is it possible? Can you kindly help me out to disable this functionality.
Thanks in advance.
7 Answers, 1 is accepted
You can substitute the built-in edit to your own custom edit form by setting the sub-property EditFormType of EditFormSettings.Please take a look into the sample code snippet using EditFormType to 'Template'.
ASPX:
<MasterTableView CommandItemDisplay=
"Top"
>
<EditFormSettings EditFormType=
"Template"
>
<FormTemplate>
<asp:TextBox ID=
"TextBox1"
runat=
"server"
></asp:TextBox>
<asp:TextBox ID=
"TextBox2"
runat=
"server"
></asp:TextBox>
. . .
. . .
</FormTemplate>
</EditFormSettings>
<Columns>
<telerik:GridBoundColumn UniqueName=
"OrderID"
HeaderText=
"OrderID"
DataField=
"OrderID"
></telerik:GridBoundColumn>
<telerik:GridBoundColumn UniqueName=
"OrderDate"
HeaderText=
"OrderDate"
DataField=
"OrderDate"
></telerik:GridBoundColumn>
. . .
. . .
</Columns>
</MasterTableView>
Please look into this help documentation for more details.
Thanks,
Shinu.
Hi Shinu,
Thanks for your reply. I am new to this telerik controls and UI.. Here is my code.
<telerik:RadGrid ID="MyImage" runat="server"
Height="" Width="37.5%"
AllowFilteringByColumn="true"
AlternatingItemStyle-Wrap="false"
OnItemDataBound="MyImage_ItemDataBound"
OnNeedDataSource="MyImage_NeedDataSource"
OnItemCommand="MyImage_ItemCommand"
OnItemCreated="MyImage_ItemCreated"
FilterMenu-EnableImageSprites="true"
ClientSettings-ClientEvents-OnGridCreated="OnMyImageCreated"
EnableLinqExpressions = "false" AllowPaging="false" PageSize="8"
>
<ClientSettings AllowRowsDragDrop="True">
<Selecting AllowRowSelect="True" EnableDragToSelectRows="true"/>
<ClientEvents OnRowDropping="onRowDropping" />
</ClientSettings>
<MasterTableView
AllowFilteringByColumn="false"
AllowNaturalSort="False"
BorderWidth="0"
CommandItemDisplay="Top"
EditMode="InPlace"
CommandItemSettings-ShowRefreshButton="False" PageSize="8" AllowPaging="false"
AutoGenerateColumns="False" DataKeyNames="ImageName">
<Columns >
<telerik:GridTemplateColumn UniqueName="CheckBoxTemplateColumn" ShowFilterIcon="false" AllowFiltering="false" >
<HeaderTemplate>
<asp:CheckBox id="headerChkbox" OnCheckedChanged="ToggleSelectedState" AutoPostBack="True" runat="server"></asp:CheckBox>
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox id="CheckBox1" OnCheckedChanged="ToggleRowSelection" AutoPostBack="True" runat="server" ></asp:CheckBox>
</ItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridBoundColumn DataField="ImageName" ShowFilterIcon="false" AllowFiltering="false"
HeaderText="Name"
SortExpression="ImageName" UniqueName="ImageName">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="DataImage"
HeaderText="DataImage" Display="false"
SortExpression="DataImage" UniqueName="DataImage">
</telerik:GridBoundColumn>
</Columns>
<CommandItemTemplate>
<div style="padding: 5px 5px;">
<telerik:RadButton ID="btnAddImage" runat="server" CommandName="InitInsert"
Text="New" ToolTip="Create a new Image" Enabled="True" BorderStyle="None"
Icon-PrimaryIconUrl="~/Images/toolbar/new.png" AutoPostBack="True"
ButtonType="LinkButton" CssClass="alignmiddle" ClientIDMode="Static"
Font-Underline="false" style="vertical-align:middle" >
</telerik:RadButton>
</CommandItemTemplate>
When I use "<EditFormSettings EditFormType=
"Template"
>
" in above implementation and remove the "<CommandItemTemplate>" i am getting exceptions. Can you please let me know, whether I am doing anything wrong here?
Thanks in advance.
I couldn't get any exception on removing the CommandItemTemplate.When the EditMode property of a table view is "EditForms" or "PopUp", the table view's EditFormSettings property lets you configure the edit form.Please use EditMode to "EditForms" or "PopUp". I am not sure why are you removing the CommandItemTemplate on configuring the edit form. I have added the EditFormSettings into your code below.Please paste the code in the code block to increase readability.
ASPX:
<
MasterTableView
AllowFilteringByColumn
=
"false"
AllowNaturalSort
=
"False"
BorderWidth
=
"0"
CommandItemDisplay
=
"Top"
EditMode
=
"EdiForms"
CommandItemSettings-ShowRefreshButton
=
"False"
PageSize
=
"8"
AllowPaging
=
"false"
AutoGenerateColumns
=
"False"
DataKeyNames
=
"ImageName"
>
<
EditFormSettings
EditFormType
=
"Template"
>
<
FormTemplate
>
<
asp:TextBox
ID
=
"TextBox1"
runat
=
"server"
></
asp:TextBox
>
<
asp:TextBox
ID
=
"TextBox2"
runat
=
"server"
></
asp:TextBox
>
</
FormTemplate
>
</
EditFormSettings
>
<
Columns
>
<
telerik:GridTemplateColumn
UniqueName
=
"CheckBoxTemplateColumn"
ShowFilterIcon
=
"false"
AllowFiltering
=
"false"
>
<
HeaderTemplate
>
<
asp:CheckBox
id
=
"headerChkbox"
OnCheckedChanged
=
"ToggleRowSelection"
AutoPostBack
=
"True"
runat
=
"server"
></
asp:CheckBox
>
</
HeaderTemplate
>
<
ItemTemplate
>
<
asp:CheckBox
id
=
"CheckBox1"
OnCheckedChanged
=
"ToggleRowSelection"
AutoPostBack
=
"True"
runat
=
"server"
></
asp:CheckBox
>
</
ItemTemplate
>
</
telerik:GridTemplateColumn
>
<
telerik:GridBoundColumn
DataField
=
"ImageName"
ShowFilterIcon
=
"false"
AllowFiltering
=
"false"
HeaderText
=
"Name"
SortExpression
=
"ImageName"
UniqueName
=
"ImageName"
></
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"DataImage"
HeaderText
=
"DataImage"
Display
=
"false"
SortExpression
=
"DataImage"
UniqueName
=
"DataImage"
></
telerik:GridBoundColumn
>
</
Columns
>
<
CommandItemTemplate
>
<
div
style
=
"padding: 5px 5px;"
>
<
telerik:RadButton
ID
=
"btnAddImage"
runat
=
"server"
CommandName
=
"InitInsert"
Text
=
"New"
ToolTip
=
"Create a new Image"
Enabled
=
"True"
BorderStyle
=
"None"
Icon-PrimaryIconUrl
=
"~/Images/index.jpg"
AutoPostBack
=
"True"
ButtonType
=
"LinkButton"
CssClass
=
"alignmiddle"
ClientIDMode
=
"Static"
Font-Underline
=
"false"
style
=
"vertical-align:middle"
>
</
telerik:RadButton
>
</
CommandItemTemplate
>
</
MasterTableView
>
Thanks,
Shinu.
Thanks for your reply. It solved my issue now. But when add one more button, I mean along with "Add" button, If I add "Edit' button. Edit forms are not coming up. I need to add anything extra? Can you kindly let me know.
Thanks in advance.
My issue got solved..
Thanks,
Geetha Rani.
I wanted to clear the edit forms. For this, I am using the following statement.
RadGridImage.MasterTableView.ClearEditItems();
But it is not doing anything. How to clear the edit forms which is in edit mode.. Is there any soluciton for this. Thanks in advance.
Thanks,
Geetha Rani.
I suppose you want to prevent opening multiple edit forms at at time. Here is the sample code that I tried which worked as expected.
C#:
protected
void
RadGrid1_ItemCommand(
object
sender, GridCommandEventArgs e)
{
switch
(Convert.ToString(e.CommandName))
{
case
"Edit"
:
RadGrid1.MasterTableView.ClearEditItems();
break
;
}
}
Thanks,
Shinu.