This is a migrated thread and some comments may be shown as answers.

[Solved] Command item Template

3 Answers 235 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Judith
Top achievements
Rank 1
Judith asked on 09 Jun 2009, 08:13 AM
In your examples you use a special SessionDataSource and asp:AccessDataSource on the asp page. At our installation we do not place datasources on the asp page - they are usually implemented as typed/non-typed datasets stored in a session variable that are bound to the grid in the grid_NeedDataSource  event: grid.DataSource = DataTable; 
What do I need to do for Command item Template model to work  as it does in your example?

3 Answers, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 09 Jun 2009, 08:58 AM
Hello Judith,

It is not obligatory to use datasource control in this case. AdvancedDataBinding with NeedDataSource should be working for you in the mentioned scenario. Could you please provide more details about the problem you face?

Best regards,
Daniel
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Judith
Top achievements
Rank 1
answered on 09 Jun 2009, 10:13 AM
Hello

the command item PerformInsert does'nt work

the code is:

ASP WEB PAGE

<%

@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

 

<%

@ Register Assembly="RadGrid.Net2" Namespace="Telerik.WebControls" TagPrefix="radG" %>

 

<!

DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

 

<

html xmlns="http://www.w3.org/1999/xhtml" >

 

<

head runat="server">

 

 

<title>Untitled Page</title>

 

</

head>

 

<

body>

 

 

<form id="form1" runat="server">

 

 

<radG:RadGrid ID="RadGrid1" Skin="Blue" Width="100%" AllowSorting="True" OnNeedDataSource="RadGrid1_NeedDataSource"

 

 

AutoGenerateColumns="true" AllowPaging="True" GridLines="None" runat="server"

 

 

ShowFooter="True" OnItemCommand="RadGrid1_ItemCommand" AllowMultiRowSelection="True"

 

 

AllowMultiRowEdit="True" HorizontalAlign="NotSet" EnableAJAX="true" OnItemDeleted="RadGrid1_ItemDeleted">

 

 

<MasterTableView GridLines="None" CommandItemDisplay="Top"

 

 

EditMode="InPlace" HorizontalAlign="NotSet" AllowAutomaticInserts="True">

 

 

<PagerStyle Mode="NextPrevAndNumeric" />

 

 

<CommandItemTemplate>

 

Custom command item template

&nbsp;

 

 

<asp:LinkButton Style="vertical-align: bottom" ID="btnEditSelected" runat="server"

 

 

CommandName="EditSelected" Visible='<%# RadGrid1.EditIndexes.Count == 0 %>'> Edit Selected Customers</asp:LinkButton>

 

 

<asp:LinkButton ID="btnUpdateEdited" runat="server" CommandName="UpdateEdited" Visible='<%# RadGrid1.EditIndexes.Count > 0 %>'><img style="border:0px" alt="" src="../../DataEditing/Img/Update.gif" /> Update Customers</asp:LinkButton>

 

 

&nbsp;

 

 

<asp:LinkButton ID="btnCancel" runat="server" CommandName="CancelAll" Visible='<%# RadGrid1.EditIndexes.Count > 0 || RadGrid1.MasterTableView.IsItemInserted %>'><img style="border:0px" alt="" src="../../DataEditing/Img/Cancel.gif" /> Cancel editing</asp:LinkButton>

 

 

&nbsp;

 

 

<asp:LinkButton ID="LinkButton2" runat="server" CommandName="InitInsert" Visible='<%# !RadGrid1.MasterTableView.IsItemInserted %>'><img style="border:0px" alt="" src="../../DataEditing/Img/AddRecord.gif" /> Add new Customer</asp:LinkButton>

 

 

<asp:LinkButton ID="LinkButton3" runat="server" CommandName="PerformInsert" Visible='<%# RadGrid1.MasterTableView.IsItemInserted %>'><img style="border:0px" alt="" src="../../DataEditing/Img/Insert.gif" /> Add this Customer</asp:LinkButton>

 

 

&nbsp;

 

 

<asp:LinkButton ID="LinkButton1" OnClientClick="javascript:return confirm('Delete all selected customers?')"

 

 

runat="server" CommandName="DeleteSelected"> Delete Selected Customers</asp:LinkButton>

 

 

&nbsp;&nbsp;&nbsp;

 

 

<asp:LinkButton ID="LinkButton4" runat="server" CommandName="RebindGrid">Refresh customer list</asp:LinkButton>

 

 

<br />

 

 

&nbsp;

 

 

</CommandItemTemplate>

 

 

</MasterTableView>

 

 

<ClientSettings>

 

 

<Selecting AllowRowSelect="True" EnableDragToSelectRows="True" />

 

 

</ClientSettings>

 

 

<FilterMenu HoverBackColor="LightSteelBlue" HoverBorderColor="Navy" NotSelectedImageUrl="~/RadControls/Grid/Skins/Default/NotSelectedMenu.gif"

 

 

SelectColumnBackColor="Control" SelectedImageUrl="~/RadControls/Grid/Skins/Default/SelectedMenu.gif"

 

 

TextColumnBackColor="Window"></FilterMenu>

 

 

<GroupPanel Visible="False">

 

 

</GroupPanel>

 

 

</radG:RadGrid>

 

 

</form>

 

 

</

body>

 

</

html>

 



ASPX CS  page

using

System;

 

using

System.Data;

 

using

System.Configuration;

 

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.WebControls;

 

using

BL;

 

public

partial class _Default : System.Web.UI.Page

 

{

 

protected void RadGrid1_NeedDataSource(object source, GridNeedDataSourceEventArgs e)

 

{

RadGrid1.DataSource =

TestRadGridManager.GetCustomers();

 

}

 

protected void Page_Load(object sender, EventArgs e)

 

{

}

 

protected void RadGrid1_ItemCommand(object source, Telerik.WebControls.GridCommandEventArgs e)

 

{

 

if (e.CommandName == "EditSelected")

 

{

 

if (RadGrid1.SelectedIndexes.Count == 0)

 

{

 

return;

 

}

 

foreach (GridDataItem item in RadGrid1.SelectedItems)

 

{

item.Edit =

true;

 

}

e.Item.OwnerTableView.Rebind();

 

return;

 

}

 

if (e.CommandName == "UpdateEdited")

 

{

 

if (RadGrid1.EditIndexes.Count == 0)

 

{

 

return;

 

}

 

foreach (GridDataItem item in RadGrid1.EditItems)

 

{

 

if (item.OwnerTableView.EditMode == GridEditMode.InPlace)

 

{

item.OwnerTableView.PerformUpdate(item,

true);

 

}

 

else

 

{

item.OwnerTableView.PerformUpdate(item.EditFormItem,

true);

 

}

}

e.Item.OwnerTableView.Rebind();

 

return;

 

}

 

if (e.CommandName == "DeleteSelected")

 

{

 

if (RadGrid1.SelectedIndexes.Count == 0)

 

{

 

return;

 

}

 

foreach (GridDataItem item in RadGrid1.SelectedItems)

 

{

e.Item.OwnerTableView.PerformDelete(item,

true);

 

}

e.Item.OwnerTableView.Rebind();

 

return;

 

}

 

if (e.CommandName == "CancelAll")

 

{

 

foreach (GridDataItem item in RadGrid1.EditItems)

 

{

item.Edit =

false;

 

}

e.Item.OwnerTableView.IsItemInserted =

false;

 

e.Item.OwnerTableView.Rebind();

 

return;

 

}

}

 

protected void RadGrid1_ItemDeleted(object source, GridDeletedEventArgs e)

 

{

e.ExceptionHandled =

true;

 

}

}



DAL

using

System;

 

using

System.Collections.Generic;

 

using

System.Text;

 

using

System.Data;

 

using

BNHP.Infrastructure.Net2;

 

using

BNHP.Infrastructure.Net2.GeneralUtils;

 

namespace

BL

 

{

 

public class TestRadGridManager

 

{

 

public static DataTable GetCustomers()

 

{

 

try

 

{

 

 

DataSet ds = DBHelper.ExecuteDataset(pf.getConnectionString(),

 

 

CommandType.Text,

 

 

"SELECT * FROM NorthWind.dbo.Customers",

 

 

DBHelper.CachingMode.NoCache,

 

 

DBHelper.CachingKeyType.NoKey,

 

 

new TimeSpan(0, 0, 0));

 

 

if (ds != null && ds.Tables != null && ds.Tables.Count > 0)

 

{

 

return ds.Tables[0];

 

}

 

return null;

 

}

 

catch (Exception ex)

 

{

 

throw new HashavException(ex.Message);

 

}

}

}

}



0
Vlad
Telerik team
answered on 12 Jun 2009, 11:25 AM
Hi Judith,

Can you verify that the grid/page ViewState is there? Generally you can find the same example with our old classic grid ASP.NET 1.x style (NeedDataSource binding) and it is still working:
http://demos1x.telerik.com/aspnet/Grid/Examples/Programming/CommandItem/DefaultCS.aspx

Best wishes,
Vlad
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
Grid
Asked by
Judith
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Judith
Top achievements
Rank 1
Vlad
Telerik team
Share this question
or