9 Answers, 1 is accepted
If you have a button with CommandName = "AddSelected" in the grid CommandItemTemplate, the grid will raise ItemCommand where you can loop on selected grid items using SelectedItems property and perform desired operation.
Best wishes,
Vlad
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.
I just try out the solution u gave but it doesn't seems working. Am i missing anything? Is good that you can provide me the sample webpage.
Thanks.
I'm not sure what exactly does not work - the grid will not raise ItemCommand?
Here is the requested example:
<telerik:RadGrid ID="RadGrid1" AllowMultiRowSelection="true" runat="server">
<MasterTableView CommandItemDisplay="Top" DataKeyNames="CustomerID">
<CommandItemTemplate>
<asp:Button ID="Button1" Text="Add Selected" CommandName="AddSelected" runat="server" />
</CommandItemTemplate>
</MasterTableView>
<ClientSettings >
<Selecting AllowRowSelect="true" />
</ClientSettings>
</telerik:RadGrid>
void RadGrid1_ItemCommand(object source, GridCommandEventArgs e)
{
if (e.CommandName == "AddSelected")
{
foreach (GridDataItem item in RadGrid1.SelectedItems)
{
Response.Write(item.GetDataKeyValue("CustomerID"));
}
}
}
Greetings,
Vlad
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Where should i include the following code?
void RadGrid1_ItemCommand(object source, GridCommandEventArgs e)
{
if (e.CommandName == "AddSelected")
{
foreach (GridDataItem item in RadGrid1.SelectedItems)
{
Response.Write(item.GetDataKeyValue("CustomerID"));
}
}
}
I'm current programming in VB. Can i have a working sample file? I'm very new to this. Thanks
Here is the converted version of the code in VB.NET language:
Sub RadGrid1_ItemCommand(ByVal source As Object, ByVal e As GridCommandEventArgs) Handles RadGrid1.ItemCommand |
If e.CommandName = "AddSelected" Then |
For Each item As GridDataItem In RadGrid1.SelectedItems |
Response.Write(item.GetDataKeyValue("CustomerID")) |
Next |
End If |
End Sub |
You may also consider using our free online converter to translate C# code in VB.NET.
Regards,
Stephen
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.
It still doesn't work. When i compile there's no error but when i click on the button an event handler error appear. Below is the code:
<%
@ Page Language="VB" MasterPageFile="~/MasterPage.master" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="Rev0PlannerV2_Default" title="Untitled Page" %>
<%
@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
<
asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<telerik:radajaxmanager id="RadAjaxManager1" runat="server"><AjaxSettings>
<
telerik:AjaxSetting AjaxControlID="RadGrid1"><UpdatedControls>
<
telerik:AjaxUpdatedControl ControlID="RadGrid1"></telerik:AjaxUpdatedControl>
</
UpdatedControls>
</
telerik:AjaxSetting>
</
AjaxSettings>
</
telerik:radajaxmanager>
<br />
<telerik:radgrid id="RadGrid1" runat="server" allowautomaticdeletes="True" allowautomaticinserts="True"
allowautomaticupdates="True" allowmultirowedit="True" allowmultirowselection="True"
allowpaging="True" autogeneratecolumns="False" autogeneratedeletecolumn="True"
autogenerateeditcolumn="True" datasourceid="SqlDataSource1" gridlines="None"
pagesize="14" showstatusbar="True" skin="WebBlue" width="97%">
<
PagerStyle Mode="Slider"></PagerStyle>
<
MasterTableView DataKeyNames="IDRev0" DataSourceID="SqlDataSource1" CommandItemDisplay="Top" Width="100%">
<
RowIndicatorColumn>
<
HeaderStyle Width="20px"></HeaderStyle>
</
RowIndicatorColumn>
<
ExpandCollapseColumn>
<
HeaderStyle Width="20px"></HeaderStyle>
</
ExpandCollapseColumn>
<
Columns>
<telerik:GridBoundColumn DataField="IDRev0" DataType="System.Int32" HeaderText="IDRev0"
ReadOnly="True" SortExpression="IDRev0" UniqueName="IDRev0">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="RevRev0" HeaderText="RevRev0" SortExpression="RevRev0"
UniqueName="RevRev0">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="TestPillarsRev0" HeaderText="TestPillarsRev0"
SortExpression="TestPillarsRev0" UniqueName="TestPillarsRev0">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="PlatformConfigRev0" HeaderText="PlatformConfigRev0"
SortExpression="PlatformConfigRev0" UniqueName="PlatformConfigRev0">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="TS_ID_Rev0" HeaderText="TS_ID_Rev0" SortExpression="TS_ID_Rev0"
UniqueName="TS_ID_Rev0">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="ID_Rev0" HeaderText="ID_Rev0" SortExpression="ID_Rev0"
UniqueName="ID_Rev0">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="TS_ID1_Rev0" HeaderText="TS_ID1_Rev0" SortExpression="TS_ID1_Rev0"
UniqueName="TS_ID1_Rev0">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="DependencyRev0" HeaderText="DependencyRev0" SortExpression="DependencyRev0"
UniqueName="DependencyRev0">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="TestCasesRev0" HeaderText="TestCasesRev0" SortExpression="TestCasesRev0"
UniqueName="TestCasesRev0">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="UseCasesRev0" HeaderText="UseCasesRev0" SortExpression="UseCasesRev0"
UniqueName="UseCasesRev0">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="PriorityRev0" HeaderText="PriorityRev0" SortExpression="PriorityRev0"
UniqueName="PriorityRev0">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="DescriptionRev0" HeaderText="DescriptionRev0"
SortExpression="DescriptionRev0" UniqueName="DescriptionRev0">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="TS_NameRev0" HeaderText="TS_NameRev0" SortExpression="TS_NameRev0"
UniqueName="TS_NameRev0">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="IOHRev0" HeaderText="IOHRev0" SortExpression="IOHRev0"
UniqueName="IOHRev0">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="BT_Rev0" HeaderText="BT_Rev0" SortExpression="BT_Rev0"
UniqueName="BT_Rev0">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="WifiRev0" HeaderText="WifiRev0" SortExpression="WifiRev0"
UniqueName="WifiRev0">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="WWAN_Rev0" HeaderText="WWAN_Rev0" SortExpression="WWAN_Rev0"
UniqueName="WWAN_Rev0">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="ThreeG_Rev0" HeaderText="ThreeG_Rev0" SortExpression="ThreeG_Rev0"
UniqueName="ThreeG_Rev0">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="WWMAX_Rev0" HeaderText="WWMAX_Rev0" SortExpression="WWMAX_Rev0"
UniqueName="WWMAX_Rev0">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="CPUH_Rev0" HeaderText="CPUH_Rev0" SortExpression="CPUH_Rev0"
UniqueName="CPUH_Rev0">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="TestAssignedRev0" HeaderText="TestAssignedRev0"
SortExpression="TestAssignedRev0" UniqueName="TestAssignedRev0">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="TesterRev0" HeaderText="TesterRev0" SortExpression="TesterRev0"
UniqueName="TesterRev0">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="MotherboardModelRev0" HeaderText="MotherboardModelRev0"
SortExpression="MotherboardModelRev0" UniqueName="MotherboardModelRev0">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="MotherboardNoRev0" HeaderText="MotherboardNoRev0"
SortExpression="MotherboardNoRev0" UniqueName="MotherboardNoRev0">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="BIOS_Rev0" HeaderText="BIOS_Rev0" SortExpression="BIOS_Rev0"
UniqueName="BIOS_Rev0">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="DisplayRev0" HeaderText="DisplayRev0" SortExpression="DisplayRev0"
UniqueName="DisplayRev0">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="CPU_NoRev0" HeaderText="CPU_NoRev0" SortExpression="CPU_NoRev0"
UniqueName="CPU_NoRev0">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="PatchRev0" HeaderText="PatchRev0" SortExpression="PatchRev0"
UniqueName="PatchRev0">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="MemoryRev0" HeaderText="MemoryRev0" SortExpression="MemoryRev0"
UniqueName="MemoryRev0">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="KitRev0" HeaderText="KitRev0" SortExpression="KitRev0"
UniqueName="KitRev0">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="BlockingIssueRev0" HeaderText="BlockingIssueRev0"
SortExpression="BlockingIssueRev0" UniqueName="BlockingIssueRev0">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="BlockingReasonPCRev0" HeaderText="BlockingReasonPCRev0"
SortExpression="BlockingReasonPCRev0" UniqueName="BlockingReasonPCRev0">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="GraphicDriverPCRev0" HeaderText="GraphicDriverPCRev0"
SortExpression="GraphicDriverPCRev0" UniqueName="GraphicDriverPCRev0">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="AudioDriverPCRev0" HeaderText="AudioDriverPCRev0"
SortExpression="AudioDriverPCRev0" UniqueName="AudioDriverPCRev0">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="LAN_DriverPCRev0" HeaderText="LAN_DriverPCRev0"
SortExpression="LAN_DriverPCRev0" UniqueName="LAN_DriverPCRev0">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="GPS_DriverPCRev0" HeaderText="GPS_DriverPCRev0"
SortExpression="GPS_DriverPCRev0" UniqueName="GPS_DriverPCRev0">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="OSnVersionPCRev0" HeaderText="OSnVersionPCRev0"
SortExpression="OSnVersionPCRev0" UniqueName="OSnVersionPCRev0">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="USB_ClientSoftwarePCRev0" HeaderText="USB_ClientSoftwarePCRev0"
SortExpression="USB_ClientSoftwarePCRev0" UniqueName="USB_ClientSoftwarePCRev0">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="GPS_SoftwareRev0" HeaderText="GPS_SoftwareRev0"
SortExpression="GPS_SoftwareRev0" UniqueName="GPS_SoftwareRev0">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="ISV_SoftwareRev0" HeaderText="ISV_SoftwareRev0"
SortExpression="ISV_SoftwareRev0" UniqueName="ISV_SoftwareRev0">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="StartRev0" DataType="System.DateTime" HeaderText="StartRev0"
SortExpression="StartRev0" UniqueName="StartRev0">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="EndRev0" DataType="System.DateTime" HeaderText="EndRev0"
SortExpression="EndRev0" UniqueName="EndRev0">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="WW_Rev0" HeaderText="WW_Rev0" SortExpression="WW_Rev0"
UniqueName="WW_Rev0">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="DurationRev0" HeaderText="DurationRev0" SortExpression="DurationRev0"
UniqueName="DurationRev0">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="ResultsRev0" HeaderText="ResultsRev0" SortExpression="ResultsRev0"
UniqueName="ResultsRev0">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="PS_ID_Rev0" HeaderText="PS_ID_Rev0" SortExpression="PS_ID_Rev0"
UniqueName="PS_ID_Rev0">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="PS_DateRev0" HeaderText="PS_DateRev0" SortExpression="PS_DateRev0"
UniqueName="PS_DateRev0">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="PS_StatusRev0" HeaderText="PS_StatusRev0" SortExpression="PS_StatusRev0"
UniqueName="PS_StatusRev0">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="SightingID_Rev0" HeaderText="SightingID_Rev0"
SortExpression="SightingID_Rev0" UniqueName="SightingID_Rev0">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="SightingDateRev0" HeaderText="SightingDateRev0"
SortExpression="SightingDateRev0" UniqueName="SightingDateRev0">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="SightingStatusRev0" HeaderText="SightingStatusRev0"
SortExpression="SightingStatusRev0" UniqueName="SightingStatusRev0">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="DebugStatusRev0" HeaderText="DebugStatusRev0"
SortExpression="DebugStatusRev0" UniqueName="DebugStatusRev0">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="PlanningCommentsRev0" HeaderText="PlanningCommentsRev0"
SortExpression="PlanningCommentsRev0" UniqueName="PlanningCommentsRev0">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="ExecutionCommentRev0" HeaderText="ExecutionCommentRev0"
SortExpression="ExecutionCommentRev0" UniqueName="ExecutionCommentRev0">
</telerik:GridBoundColumn>
</
Columns>
<
EditFormSettings ColumnNumber="2" CaptionDataField="IDRev0" CaptionFormatString="Edit properties of IDRev0 {0}">
<
EditColumn ButtonType="ImageButton" CancelText="Cancel edit" UpdateText="Update record" InsertText="Insert Order" UniqueName="EditCommandColumn1"></EditColumn>
<
FormTableStyle CellPadding="2" CellSpacing="0" BackColor="White" CssClass="module" Height="110px"></FormTableStyle>
<
FormMainTableStyle CellPadding="3" CellSpacing="0" GridLines="Horizontal" BackColor="White" Width="100%"></FormMainTableStyle>
<
FormCaptionStyle CssClass="EditFormHeader"></FormCaptionStyle>
<
FormTableItemStyle Wrap="False"></FormTableItemStyle>
<
FormTableAlternatingItemStyle Wrap="False"></FormTableAlternatingItemStyle>
<
FormTableButtonRowStyle HorizontalAlign="Right" CssClass="EditFormButtonRow"></FormTableButtonRowStyle>
</
EditFormSettings>
<
CommandItemTemplate>
<div style="padding:10px 0px;">
Custom command item template
<asp:LinkButton Style="vertical-align: bottom" ID="btnEditSelected" runat="server"
CommandName="EditSelected" CausesValidation="false" Visible='<%# RadGrid1.EditIndexes.Count = 0 %>'><img style="border:0px;vertical-align:middle;" alt="" src="../../DataEditing/Img/Edit.gif" /> Edit Selected Products</asp:LinkButton>
<asp:LinkButton ID="btnUpdateEdited" runat="server" CommandName="UpdateEdited" Visible='<%# RadGrid1.EditIndexes.Count > 0 %>'><img style="border:0px;vertical-align:middle;" alt="" src="../../DataEditing/Img/Update.gif" /> Update Products</asp:LinkButton>
<asp:LinkButton ID="btnCancel" runat="server" CommandName="CancelAll" CausesValidation="false" Visible='<%# RadGrid1.EditIndexes.Count > 0 Or RadGrid1.MasterTableView.IsItemInserted %>'><img style="border:0px;vertical-align:middle;" alt="" src="../../DataEditing/Img/Cancel.gif" /> Cancel editing</asp:LinkButton>
<asp:LinkButton ID="LinkButton2" runat="server" CommandName="InitInsert" Visible='<%# Not RadGrid1.MasterTableView.IsItemInserted %>'><img style="border:0px;vertical-align:middle;" alt="" src="../../DataEditing/Img/AddRecord.gif" /> Add new Product</asp:LinkButton>
<asp:LinkButton ID="LinkButton3" runat="server" CommandName="PerformInsert" Visible='<%# RadGrid1.MasterTableView.IsItemInserted %>'><img style="border:0px;vertical-align:middle;" alt="" src="../../DataEditing/Img/Insert.gif" /> Add this Product</asp:LinkButton>
<asp:LinkButton ID="LinkButton1" OnClientClick="javascript:return confirm('Delete all selected Products?')"
runat="server" CommandName="DeleteSelected" CausesValidation="false" ><img style="border:0px;vertical-align:middle;" alt="" src="../../DataEditing/Img/Delete.gif" /> Delete Selected Products</asp:LinkButton>
<asp:LinkButton ID="LinkButton4" runat="server" CommandName="RebindGrid"><img style="border:0px;vertical-align:middle;" alt="" src="../../DataEditing/Img/Refresh.gif" /> Refresh Products</asp:LinkButton>
<br />
<asp:LinkButton ID="LinkButton5" runat="server" CommandName="AddSelected" Text="Add Selected"
Visible="<%# RadGrid1.EditIndexes.Count = 0 %>">LinkButton</asp:LinkButton></div>
</
CommandItemTemplate>
</
MasterTableView>
<
ClientSettings>
<
Selecting AllowRowSelect="True"></Selecting>
</
ClientSettings>
<
FilterMenu Skin="WebBlue" EnableTheming="True">
<
CollapseAnimation Type="OutQuint" Duration="200"></CollapseAnimation>
</
FilterMenu>
</
telerik:radgrid>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:Rev0DatabaseConnectionString %>"
What could be wrong???
What is the error you receive - can you post its stack trace here? I suppose it will be sufficient to pinpoint the source of the problem and address it.
Regards,
Stephen
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Sys.webforms.PageRequestManagerParsErerrorException:The message received from the server could not be parsed. Common causes for this error are when the response is modified by calls to Response.Write(),response filters, HttpModules, or server trace is enabled. Details: Error parsing near "Manager1"));
});
|'.
Please help. Thanks.
To progress in our investigation, I suggest you prepare a stripped working version of your project, demonstrating the erratic behavior, and send it enclosed to a formal support ticket which you can start from your Client.NET account. I will test/debug it locally and will advice you further.
Regards,
Stephen
the Telerik team
Check out Telerik Trainer, the state of the art learning tool for Telerik products.