Hi Dorababu,
Please take a look into the following code snippet i tried to achieve the same scenario.
ASPX:
<
telerik:RadScriptManager
ID
=
"ScriptManager1"
runat
=
"server"
/>
<
telerik:RadCodeBlock
runat
=
"server"
ID
=
"RadCodeBlock1"
>
<
script
type
=
"text/javascript"
>
function RowContextMenu(sender, eventArgs) {
var menu = $find("<%=RadMenu1.ClientID %>");
var evt = eventArgs.get_domEvent();
if (evt.target.tagName == "INPUT" || evt.target.tagName == "A") {
return;
}
var index = eventArgs.get_itemIndexHierarchical();
document.getElementById("radGridClickedRowIndex").value = index;
sender.get_masterTableView().selectItem(sender.get_masterTableView().get_dataItems()[index].get_element(), true);
menu.show(evt);
evt.cancelBubble = true;
evt.returnValue = false;
if (evt.stopPropagation) {
evt.stopPropagation();
evt.preventDefault();
}
}
</
script
>
</
telerik:RadCodeBlock
>
<
telerik:RadAjaxManager
ID
=
"RadAjaxManager1"
runat
=
"server"
EnableAJAX
=
"false"
>
<
AjaxSettings
>
<
telerik:AjaxSetting
AjaxControlID
=
"RadGrid1"
>
<
UpdatedControls
>
<
telerik:AjaxUpdatedControl
ControlID
=
"RadGrid1"
LoadingPanelID
=
"RadAjaxLoadingPanel1"
/>
<
telerik:AjaxUpdatedControl
ControlID
=
"RadMenu1"
/>
</
UpdatedControls
>
</
telerik:AjaxSetting
>
<
telerik:AjaxSetting
AjaxControlID
=
"RadMenu1"
>
<
UpdatedControls
>
<
telerik:AjaxUpdatedControl
ControlID
=
"RadGrid1"
LoadingPanelID
=
"RadAjaxLoadingPanel1"
/>
<
telerik:AjaxUpdatedControl
ControlID
=
"RadMenu1"
/>
</
UpdatedControls
>
</
telerik:AjaxSetting
>
</
AjaxSettings
>
</
telerik:RadAjaxManager
>
<
telerik:RadAjaxLoadingPanel
ID
=
"RadAjaxLoadingPanel1"
runat
=
"server"
/>
<
input
type
=
"hidden"
id
=
"radGridClickedRowIndex"
name
=
"radGridClickedRowIndex"
/>
<
div
style
=
"margin-right: 20px;"
>
<
telerik:RadGrid
ID
=
"RadGrid1"
runat
=
"server"
Width
=
"100%"
DataSourceID
=
"SqlDataSource1"
AllowAutomaticDeletes
=
"true"
AllowAutomaticInserts
=
"true"
AllowAutomaticUpdates
=
"true"
OnPreRender
=
"RadGrid1_PreRender"
OnUpdateCommand
=
"RadGrid1_UpdateCommand"
>
<
MasterTableView
AllowSorting
=
"False"
PageSize
=
"10"
AllowPaging
=
"True"
Width
=
"100%"
DataKeyNames
=
"ProductID"
DataSourceID
=
"SqlDataSource1"
EditMode
=
"InPlace"
>
<
Columns
>
<
telerik:GridEditCommandColumn
UniqueName
=
"EditCommandColumn"
Visible
=
"false"
/>
</
Columns
>
</
MasterTableView
>
<
ClientSettings
>
<
ClientEvents
OnRowContextMenu
=
"RowContextMenu"
></
ClientEvents
>
<
Selecting
AllowRowSelect
=
"true"
/>
</
ClientSettings
>
<
PagerStyle
Mode
=
"NextPrevAndNumeric"
/>
</
telerik:RadGrid
>
</
div
>
<
br
/>
<
asp:SqlDataSource
ID
=
"SqlDataSource1"
runat
=
"server"
ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString3 %>"
DeleteCommand="DELETE FROM [Products] WHERE [ProductID] = @ProductID" InsertCommand="INSERT INTO [Products] ([ProductName], [UnitPrice], [UnitsInStock]) VALUES (@ProductName, @UnitPrice, @UnitsInStock)"
SelectCommand="SELECT [ProductID], [ProductName], [UnitPrice], [UnitsInStock] FROM [Products]"
UpdateCommand="UPDATE [Products] SET [ProductName] = @ProductName, [UnitPrice] = @UnitPrice, [UnitsInStock] = @UnitsInStock WHERE [ProductID] = @ProductID">
<
DeleteParameters
>
<
asp:Parameter
Name
=
"ProductID"
Type
=
"Int32"
/>
</
DeleteParameters
>
<
InsertParameters
>
<
asp:Parameter
Name
=
"ProductName"
Type
=
"String"
/>
<
asp:Parameter
Name
=
"UnitPrice"
Type
=
"Decimal"
/>
<
asp:Parameter
Name
=
"UnitsInStock"
Type
=
"Int16"
/>
</
InsertParameters
>
<
UpdateParameters
>
<
asp:Parameter
Name
=
"ProductName"
Type
=
"String"
/>
<
asp:Parameter
Name
=
"UnitPrice"
Type
=
"Decimal"
/>
<
asp:Parameter
Name
=
"UnitsInStock"
Type
=
"Int16"
/>
<
asp:Parameter
Name
=
"ProductID"
Type
=
"Int32"
/>
</
UpdateParameters
>
</
asp:SqlDataSource
>
<
telerik:RadContextMenu
ID
=
"RadMenu1"
runat
=
"server"
OnItemClick
=
"RadMenu1_ItemClick"
EnableRoundedCorners
=
"true"
EnableShadows
=
"true"
>
<
Items
>
<
telerik:RadMenuItem
Text
=
"Add"
/>
<
telerik:RadMenuItem
Text
=
"Edit"
/>
<
telerik:RadMenuItem
Text
=
"Delete"
/>
</
Items
>
</
telerik:RadContextMenu
>
C#:
protected
void
RadGrid1_PreRender(
object
sender, EventArgs e)
{
if
(RadGrid1.EditIndexes.Count > 0 || RadGrid1.MasterTableView.IsItemInserted)
{
GridColumn col1 = RadGrid1.MasterTableView.GetColumn(
"EditCommandColumn"
);
col1.Visible =
true
;
}
else
{
GridColumn col2 = RadGrid1.MasterTableView.GetColumn(
"EditCommandColumn"
);
col2.Visible =
false
;
}
(RadGrid1.MasterTableView.AutoGeneratedColumns[0]
as
GridBoundColumn).ReadOnly =
true
;
}
protected
void
RadMenu1_ItemClick(
object
sender, RadMenuEventArgs e)
{
int
radGridClickedRowIndex;
radGridClickedRowIndex = Convert.ToInt32(Request.Form[
"radGridClickedRowIndex"
]);
switch
(e.Item.Text)
{
case
"Edit"
:
RadGrid1.Items[radGridClickedRowIndex].Edit =
true
;
RadGrid1.Rebind();
break
;
case
"Add"
:
RadGrid1.MasterTableView.IsItemInserted =
true
;
RadGrid1.Rebind();
break
;
case
"Delete"
:
int
index1 = Convert.ToInt16(radGridClickedRowIndex);
if
(index1== 0)
{
RadGrid1.MasterTableView.PerformDelete(RadGrid1.Items[radGridClickedRowIndex]);
}
else
{
Response.Write(
"<script>alert('Please upload pdf files only');</script>"
);
}
break
;
}
}
//Performs validation of UnitPrice and UnitsInStock values.
protected
void
RadGrid1_UpdateCommand(
object
sender, GridCommandEventArgs e)
{
GridTextColumnEditor gridTextColumnEditor_UnitPrice = (e.Item
as
GridDataItem).EditManager.GetColumnEditor(
"UnitPrice"
)
as
GridTextColumnEditor;
GridTextColumnEditor gridTextColumnEditor_UnitsInStock = (e.Item
as
GridDataItem).EditManager.GetColumnEditor(
"UnitsInStock"
)
as
GridTextColumnEditor;
if
(gridTextColumnEditor_UnitsInStock.Text == String.Empty)
{
e.Canceled =
true
;
SetDefaultValues(gridTextColumnEditor_UnitsInStock,
"0"
);
}
if
(gridTextColumnEditor_UnitPrice.Text == String.Empty)
{
e.Canceled =
true
;
SetDefaultValues(gridTextColumnEditor_UnitPrice,
"0"
);
}
else
if
(gridTextColumnEditor_UnitPrice.Text.Split(
'.'
)[0].Length <= 0 || gridTextColumnEditor_UnitPrice.Text.Split(
'.'
)[0].Length > 3)
{
e.Canceled =
true
;
SetDefaultValues(gridTextColumnEditor_UnitPrice,
"0"
);
}
}
private
void
SetDefaultValues(GridTextColumnEditor gridTextColumnEditor,
string
text)
{
gridTextColumnEditor.Text = text;
}
Thanks,
Shinu.