Folks I am using VS 2010 SP1 and RadControls for ASP.NET AJAX Q1 2012. I would like the following steps if possible in Rad Grid:
1) After Edit, highlight the last edited row in Grid.
2) After Insert, without any user interaction (automatically)
A) Retrieve the Primary Key value of newly inserted row,
B) Highlight (Select) newly inserted row in Grid
C) Open the newly inserted row in Edit Mode to enter some additional data that are not required in initial insert.
D) Show the Primary Key Value of newly inserted row in a Label in Edit Form.
3) After user Updates or Cancel in Step 2, do Step #1 (i.e. highlight the last edited row in Grid)
Is these above possible?
I am using below link as sample (RadGrid2). and attached is my code.
http://demos.telerik.com/aspnet-ajax/grid/examples/programming/commanditem/defaultcs.aspx
Thanks
GC_0620
-------------------
_____________
1) After Edit, highlight the last edited row in Grid.
2) After Insert, without any user interaction (automatically)
A) Retrieve the Primary Key value of newly inserted row,
B) Highlight (Select) newly inserted row in Grid
C) Open the newly inserted row in Edit Mode to enter some additional data that are not required in initial insert.
D) Show the Primary Key Value of newly inserted row in a Label in Edit Form.
3) After user Updates or Cancel in Step 2, do Step #1 (i.e. highlight the last edited row in Grid)
Is these above possible?
I am using below link as sample (RadGrid2). and attached is my code.
http://demos.telerik.com/aspnet-ajax/grid/examples/programming/commanditem/defaultcs.aspx
Thanks
GC_0620
-------------------
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="DefaultCS.aspx.cs" Inherits="Grid.Examples.Programming.CommandItem.DefaultCS" %>
<%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<
html
xmlns
=
"http://www.w3.org/1999/xhtml"
>
<
head
runat
=
"server"
>
<!-- custom head section -->
<
style
type
=
"text/css"
>
.bigModuleBottom td
{
padding: 0;
}
</
style
>
<!-- end of custom head section -->
</
head
>
<
body
class
=
"BODY"
>
<
form
runat
=
"server"
id
=
"mainForm"
method
=
"post"
>
<
telerik:RadScriptManager
ID
=
"RadScriptManager1"
runat
=
"server"
/>
<!-- content start -->
<
telerik:RadCodeBlock
ID
=
"RadCodeBlock1"
runat
=
"server"
>
<
script
type
=
"text/javascript"
>
function RowDblClick(sender, eventArgs) {
sender.get_masterTableView().editItem(eventArgs.get_itemIndexHierarchical());
}
</
script
>
</
telerik:RadCodeBlock
>
<
telerik:RadAjaxManager
ID
=
"RadAjaxManager1"
runat
=
"server"
>
<
AjaxSettings
>
<
telerik:AjaxSetting
AjaxControlID
=
"RadGrid2"
>
<
UpdatedControls
>
<
telerik:AjaxUpdatedControl
ControlID
=
"RadGrid2"
/>
<
telerik:AjaxUpdatedControl
ControlID
=
"Label3"
/>
<
telerik:AjaxUpdatedControl
ControlID
=
"Label4"
/>
</
UpdatedControls
>
</
telerik:AjaxSetting
>
</
AjaxSettings
>
</
telerik:RadAjaxManager
>
<
div
>
<
asp:Label
ID
=
"Label1"
runat
=
"server"
EnableViewState
=
"False"
Font-Bold
=
"True"
ForeColor
=
"#FF8080"
></
asp:Label
>
<
asp:Label
ID
=
"Label2"
runat
=
"server"
EnableViewState
=
"False"
Font-Bold
=
"True"
ForeColor
=
"#00C000"
></
asp:Label
>
</
div
>
<
br
/>
<
br
/>
<
br
/>
<
br
/>
<
div
class
=
"bigModule"
>
<
div
class
=
"bigModuleBottom"
>
<%--<
div
class
=
"title"
>
Default command-item outlook</
div
>--%>
</
div
>
</
div
>
<
br
/>
<
div
>
<
asp:Label
ID
=
"Label3"
runat
=
"server"
EnableViewState
=
"False"
Font-Bold
=
"True"
ForeColor
=
"#FF8080"
></
asp:Label
>
<
asp:Label
ID
=
"Label4"
runat
=
"server"
EnableViewState
=
"False"
Font-Bold
=
"True"
ForeColor
=
"#00C000"
></
asp:Label
>
</
div
>
<
br
/>
<
telerik:RadGrid
ID
=
"RadGrid2"
DataSourceID
=
"SqlDataSource2"
AllowSorting
=
"True"
AllowAutomaticInserts
=
"true"
AllowAutomaticUpdates
=
"true"
AllowAutomaticDeletes
=
"true"
PageSize
=
"7"
AllowPaging
=
"True"
GridLines
=
"None"
runat
=
"server"
ShowFooter
=
"True"
OnItemCreated
=
"RadGrid_ItemCreated"
OnItemDeleted
=
"RadGrid_ItemDeleted"
OnItemUpdated
=
"RadGrid_ItemUpdated"
OnItemInserted
=
"RadGrid_ItemInserted"
Skin
=
"Vista"
OnItemCommand
=
"RadGrid2_ItemCommand"
>
<
PagerStyle
Mode
=
"NextPrevAndNumeric"
/>
<
MasterTableView
Width
=
"100%"
CommandItemDisplay
=
"TopAndBottom"
DataSourceID
=
"SqlDataSource2"
InsertItemPageIndexAction
=
"ShowItemOnCurrentPage"
DataKeyNames
=
"CustomerID"
AutoGenerateColumns
=
"false"
InsertItemDisplay
=
"Top"
>
<
Columns
>
<
telerik:GridEditCommandColumn
>
</
telerik:GridEditCommandColumn
>
<
telerik:GridBoundColumn
DataField
=
"CustomerID"
UniqueName
=
"CustomerID"
HeaderText
=
"Customer ID"
MaxLength
=
"5"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"CompanyName"
UniqueName
=
"CompanyName"
HeaderText
=
"Company Name"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"ContactName"
UniqueName
=
"ContactName"
HeaderText
=
"Contact Name"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"ContactTitle"
UniqueName
=
"ContactTitle"
HeaderText
=
"Contact Title"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"Address"
UniqueName
=
"Address"
HeaderText
=
"Address"
>
</
telerik:GridBoundColumn
>
<
telerik:GridBoundColumn
DataField
=
"City"
UniqueName
=
"City"
HeaderText
=
"City"
>
</
telerik:GridBoundColumn
>
<
telerik:GridButtonColumn
CommandName
=
"Delete"
Text
=
"Delete"
UniqueName
=
"DeleteColumn"
>
</
telerik:GridButtonColumn
>
</
Columns
>
<
CommandItemSettings
AddNewRecordText
=
"Add new record"
AddNewRecordImageUrl
=
"Images/AddRecord.gif"
RefreshText
=
"Refresh"
RefreshImageUrl
=
"Images/Refresh.gif"
/>
</
MasterTableView
>
<
ClientSettings
>
<
ClientEvents
OnRowDblClick
=
"RowDblClick"
/>
</
ClientSettings
>
</
telerik:RadGrid
>
<
br
/>
<
asp:SqlDataSource
ID
=
"SqlDataSource2"
runat
=
"server"
ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString35 %>"
DeleteCommand="DELETE FROM [Customers] WHERE [CustomerID] = @CustomerID" InsertCommand="INSERT INTO [Customers] ([CustomerID], [CompanyName], [ContactName], [ContactTitle], [Address], [City]) VALUES (@CustomerID, @CompanyName, @ContactName, @ContactTitle, @Address, @City)"
SelectCommand="SELECT [CustomerID], [CompanyName], [ContactName], [ContactTitle], [Address], [City] FROM [Customers]"
UpdateCommand="UPDATE [Customers] SET [CompanyName] = @CompanyName, [ContactName] = @ContactName, [ContactTitle] = @ContactTitle, [Address] = @Address, [City] = @City WHERE [CustomerID] = @CustomerID">
<
DeleteParameters
>
<
asp:Parameter
Name
=
"CustomerID"
Type
=
"String"
/>
</
DeleteParameters
>
<
InsertParameters
>
<
asp:Parameter
Name
=
"CustomerID"
Type
=
"String"
/>
<
asp:Parameter
Name
=
"CompanyName"
Type
=
"String"
/>
<
asp:Parameter
Name
=
"ContactName"
Type
=
"String"
/>
<
asp:Parameter
Name
=
"ContactTitle"
Type
=
"String"
/>
<
asp:Parameter
Name
=
"Address"
Type
=
"String"
/>
<
asp:Parameter
Name
=
"City"
Type
=
"String"
/>
</
InsertParameters
>
<
UpdateParameters
>
<
asp:Parameter
Name
=
"CompanyName"
Type
=
"String"
/>
<
asp:Parameter
Name
=
"ContactName"
Type
=
"String"
/>
<
asp:Parameter
Name
=
"ContactTitle"
Type
=
"String"
/>
<
asp:Parameter
Name
=
"Address"
Type
=
"String"
/>
<
asp:Parameter
Name
=
"City"
Type
=
"String"
/>
<
asp:Parameter
Name
=
"CustomerID"
Type
=
"String"
/>
</
UpdateParameters
>
</
asp:SqlDataSource
>
<!-- content end -->
<
p
>
</
p
>
</
form
>
</
body
>
</
html
>
_____________
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Telerik.Web.UI;
namespace Grid.Examples.Programming.CommandItem
{
public partial class DefaultCS : System.Web.UI.Page
{
protected void RadGrid_ItemCreated(object sender, GridItemEventArgs e)
{
GridEditableItem item = e.Item as GridEditableItem;
if (item != null && e.Item.IsInEditMode && e.Item.ItemIndex != -1)
{
(item.EditManager.GetColumnEditor("CustomerID").ContainerControl.Controls[0] as TextBox).Enabled = false;
}
}
protected void RadGrid_ItemUpdated(object source, Telerik.Web.UI.GridUpdatedEventArgs e)
{
if (e.Exception != null)
{
e.KeepInEditMode = true;
e.ExceptionHandled = true;
DisplayMessage(true, "Customer " + e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["CustomerID"] + " cannot be updated due to invalid data.");
}
else
{
DisplayMessage(false, "Customer " + e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["CustomerID"] + " updated");
}
}
protected void RadGrid_ItemInserted(object source, GridInsertedEventArgs e)
{
if (e.Exception != null)
{
e.ExceptionHandled = true;
e.KeepInInsertMode = true;
DisplayMessage(true, "Customer cannot be inserted due to invalid data.");
}
else
{
DisplayMessage(false, "Customer inserted");
}
e.Item.Edit = true;
}
protected void RadGrid_ItemDeleted(object source, GridDeletedEventArgs e)
{
if (e.Exception != null)
{
e.ExceptionHandled = true;
DisplayMessage(true, "Customer " + e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["CustomerID"] + " cannot be deleted");
}
else
{
DisplayMessage(false, "Customer " + e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["CustomerID"] + " deleted");
}
}
private void DisplayMessage(bool isError, string text)
{
if (isError)
{
this.Label1.Text = text;
this.Label3.Text = text;
}
else
{
this.Label2.Text = text;
this.Label4.Text = text;
}
}
protected void RadGrid2_ItemCommand(object sender, GridCommandEventArgs e)
{
}
}
}