Hi Everyone,
I have a grid in aspx page like below side..
<
div>
<telerik:RadScriptManager ID="RadScriptManager1" runat="server">
</telerik:RadScriptManager>
<telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
<script type="text/javascript">
function RowDblClick(sender, eventArgs) {
sender.get_masterTableView().editItem(eventArgs.get_itemIndexHierarchical());
}
</script>
<
style type="text/css">
.EditFormHeader td
{
background: #dadec8;
padding: 5px 0px;
}
</style>
</telerik:RadCodeBlock>
<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
<AjaxSettings>
<telerik:AjaxSetting AjaxControlID="radGridProduct">
<UpdatedControls>
<telerik:AjaxUpdatedControl ControlID="radGridProduct" />
<telerik:AjaxUpdatedControl ControlID="divMsg" />
</UpdatedControls>
</telerik:AjaxSetting>
</AjaxSettings>
</telerik:RadAjaxManager>
<div id="divMsg" runat="server" style="float: left;">
<asp:Label ID="Label1" runat="server" EnableViewState="False" Visible="false"></asp:Label>
</div>
<br />
<telerik:RadGrid ID="radGridProduct" runat="server" ShowStatusBar="true" OnNeedDataSource="radGridProduct_NeedDataSource"
GridLines="None" AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False"
OnPreRender="radGridProduct_PreRender" AllowAutomaticInserts="True"
AllowAutomaticUpdates="True" HorizontalAlign="NotSet"
OnItemInserted="radGridProduct_ItemInserted" OnItemUpdated="radGridProduct_ItemUpdated">
<MasterTableView DataKeyNames="ID" GridLines="None" Width="100%">
<Columns>
<telerik:GridEditCommandColumn UniqueName="EditCommandColumn">
</telerik:GridEditCommandColumn>
<%
-- <telerik:GridBoundColumn Visible="False" UniqueName="ID" HeaderText="ID"
DataField="ID" EditFormColumnIndex="1">
</telerik:GridBoundColumn>--
%>
<%
-- <telerik:GridBoundColumn Visible="False" UniqueName="City" HeaderText="City" DataField="City"
EditFormColumnIndex="1">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn Visible="False" UniqueName="Region" HeaderText="Region"
DataField="Region" EditFormColumnIndex="2">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn Visible="False" UniqueName="TitleOfCourtesy" HeaderText="TOC"
DataField="TitleOfCourtesy" EditFormColumnIndex="2">
<HeaderStyle Width="60px"></HeaderStyle>
</telerik:GridBoundColumn>--
%>
<telerik:GridBoundColumn UniqueName="ProductName" EditFormColumnIndex="0" HeaderText="ProductName"
DataField="ProductName">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn UniqueName="SKU" EditFormColumnIndex="0" HeaderText="SKU"
DataField="SKU">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn UniqueName="CreatedOn" EditFormColumnIndex="0"
HeaderText="Created Date" DataField="CreatedOn">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn UniqueName="Active" EditFormColumnIndex="1" HeaderText="Active"
DataField="Active">
</telerik:GridBoundColumn>
</Columns>
<EditFormSettings ColumnNumber="4" CaptionFormatString="Edit details for product: {0}"
CaptionDataField="ProductName">
<FormTableItemStyle Wrap="False"></FormTableItemStyle>
<FormCaptionStyle CssClass="EditFormHeader"></FormCaptionStyle>
<FormMainTableStyle GridLines="None" CellSpacing="0" CellPadding="3" Width="100%" />
<FormTableStyle GridLines="Horizontal" CellSpacing="0" CellPadding="2" CssClass="module"
Height="110px" Width="100%" />
<FormTableAlternatingItemStyle Wrap="False"></FormTableAlternatingItemStyle>
<FormStyle Width="100%" BackColor="#eef2ea"></FormStyle>
<EditColumn UpdateText="Update record" UniqueName="EditCommandColumn1" CancelText="Cancel edit">
</EditColumn>
<FormTableButtonRowStyle HorizontalAlign="Left" CssClass="EditFormButtonRow"></FormTableButtonRowStyle>
</EditFormSettings>
<ExpandCollapseColumn ButtonType="ImageButton" Visible="False" UniqueName="ExpandColumn">
<HeaderStyle Width="19px"></HeaderStyle>
</ExpandCollapseColumn>
</MasterTableView>
<ClientSettings>
<ClientEvents OnRowDblClick="RowDblClick" />
</ClientSettings>
</telerik:RadGrid>
</
div>
</
asp:Content>
This is code behind code -
using
System;
using
System.Collections.Generic;
using
System.Drawing;
using
System.Data;
using
Telerik.Web.UI;
public
partial class Users_ProductList : System.Web.UI.Page
{
static DataTable dtProduct = null;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
IList<TProduct> productlist = CacheHelper.edPortalService.GetProducts();
if (productlist != null && productlist.Count > 0)
dtProduct =
CollectionHelper.ConvertTo<TProduct>(productlist);
}
else
this.radGridProduct.MasterTableView.Items[1].Edit = true;
}
protected void radGridProduct_ItemUpdated(object source, Telerik.Web.UI.GridUpdatedEventArgs e)
{
if (e.Exception != null)
{
e.KeepInEditMode =
true;
e.ExceptionHandled =
true;
DisplayMessage(
true, "Product " + e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["ID"] + " cannot be updated. Reason: " + e.Exception.Message);
}
else
{
DisplayMessage(
false, "Product " + e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["ID"] + " updated");
}
}
protected void radGridProduct_ItemInserted(object source, GridInsertedEventArgs e)
{
if (e.Exception != null)
{
e.ExceptionHandled =
true;
e.KeepInInsertMode =
true;
DisplayMessage(
true, "Product cannot be inserted. Reason: " + e.Exception.Message);
}
else
{
DisplayMessage(
false, "Product inserted");
}
}
private void DisplayMessage(bool isError, string text)
{
this.Label1.Font.Bold = true;
this.Label1.Visible = true;
if (isError)
{
this.Label1.ForeColor = Color.Red;
}
else
{
this.Label1.ForeColor = Color.Green;
}
this.Label1.Text = text;
}
protected void radGridProduct_NeedDataSource(object source, GridNeedDataSourceEventArgs e)
{
BindProductGrid();
}
private void BindProductGrid()
{
if (dtProduct != null && dtProduct.Rows.Count > 0)
radGridProduct.DataSource = dtProduct;
}
protected void radGridProduct_PreRender(object sender, System.EventArgs e)
{
// if (!this.IsPostBack)
// {
// this.radGridProduct.MasterTableView.Items[1].Edit = true;
// this.radGridProduct.MasterTableView.Rebind();
// }
}
}
can someone help me where i am lacking as my update link is not working and even while i click on cancel link for any row then it always open second row in grid for cancel .
Any suggestion.