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

Can't get the RadGrid to work (OnDeleteCommand, OnUpdateCommand)

1 Answer 214 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Erik Hennerfors
Top achievements
Rank 1
Erik Hennerfors asked on 20 Apr 2010, 09:52 AM
I can't understand why my RadGrid doesn't work. Nothing triggers when i press delete, update! The Ajax image just comes up. And if i select a row the SelectColumn gets selected but triggers an Ajax update and the checkbox gets unchecked!

<%@ Page Language="C#" MasterPageFile="~/Page.Master" AutoEventWireup="true" CodeBehind="ManageUsers.aspx.cs" Inherits="Adeprimo.Tulo.Web.User.Administration.ManageUsers" Title="Untitled Page" %> 
<asp:Content ID="Content1" ContentPlaceHolderID="ctpHead" runat="server"
</asp:Content> 
<asp:Content ID="Content2" ContentPlaceHolderID="ctpMain" runat="server"
    <div id="Layout"
        <div class="typography"
            <h2><asp:Literal runat="server" ID="litLocalizationForgotPassword" Text="<%$ Resources:Default,User_ManageUsers%>" /></h2
        </div> 
    </div> 
    <div style="clear: both;"
        <telerik:RadAjaxManager ID="RadAjaxManager" runat="server"
            <AjaxSettings> 
                <telerik:AjaxSetting AjaxControlID="rdgUsers"
                    <UpdatedControls> 
                        <telerik:AjaxUpdatedControl ControlID="rdgUsers" LoadingPanelID="RadAjaxLoadingPanel" /> 
                    </UpdatedControls> 
                </telerik:AjaxSetting>                                                   
            </AjaxSettings> 
        </telerik:RadAjaxManager> 
        <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel" runat="server" /> 
    </div> 
    <telerik:RadGrid ID="rdgUsers" runat="server" EnableEmbeddedSkins="true" Skin="Black" AllowSorting="true" AllowMultiRowSelection="true" 
        OnUpdateCommand="UpdateCommand" OnInsertCommand="InsertCommmand" OnDeleteCommand="DeleteCommand"
        <MasterTableView Width="100%" ShowHeadersWhenNoRecords="true" HorizontalAlign="NotSet" 
            ExpandCollapseColumn-Display="true" AutoGenerateColumns="False" 
            DataKeyNames="UserName" EditItemStyle-HorizontalAlign="Left" > 
            <Columns> 
                <telerik:GridClientSelectColumn UniqueName="column" /> 
                <telerik:GridBoundColumn DataField="UserName" HeaderText="User Name" UniqueName="UserName" /> 
                <telerik:GridTemplateColumn DataField="Email" UniqueName="Email" HeaderText="Email" Visible="true"
                    <ItemTemplate> 
                        <%#DataBinder.Eval(Container.DataItem, "Email")%> 
                    </ItemTemplate> 
                    <EditItemTemplate> 
                        <telerik:RadComboBox ID="rcbCoutry" runat="server" AppendDataBoundItems="true" DataTextField="Country" DataValueField="Country"
                            <Items> 
                                <telerik:RadComboBoxItem Text="Sverige" Value="0" Visible="false" /> 
                                <telerik:RadComboBoxItem Value="1" Text="Finland" /> 
                            </Items> 
                        </telerik:RadComboBox> 
                    </EditItemTemplate> 
                </telerik:GridTemplateColumn> 
                <telerik:GridBoundColumn DataField="IsApproved" HeaderText="Is Approved" UniqueName="IsApproved" /> 
                <telerik:GridBoundColumn DataField="LastLoginDate" HeaderText="Last Login" UniqueName="LastLoginDate" /> 
                 
                <telerik:GridEditCommandColumn ButtonType="ImageButton" UniqueName="EditCustomer" 
                    EditText="Edit" ItemStyle-HorizontalAlign="Right"
                </telerik:GridEditCommandColumn> 
                <telerik:GridButtonColumn ConfirmText="Are you sure you wan't to delete this user?" ConfirmDialogType="RadWindow" 
                    ConfirmTitle="Delete" ButtonType="ImageButton" CommandName="Delete" Text="Delete" 
                    UniqueName="DeleteColumn"
                </telerik:GridButtonColumn> 
            </Columns> 
            <EditFormSettings EditColumn-UpdateText="Uppdatera" EditFormType="AutoGenerated"
                <EditColumn ButtonType="PushButton" UpdateText="Update" EditText="Edit" 
                    EditFormColumnIndex="5" FooterStyle-BorderStyle="Solid" HeaderButtonType="PushButton" 
                    InsertText="Save" CancelText="Cancel"
                </EditColumn> 
            </EditFormSettings> 
            <PagerStyle Mode="NextPrevAndNumeric" AlwaysVisible="true" PagerTextFormat="{4}Sida {0} av {1}, visar användare {2} av {3} av totalt {5}" 
                FirstPageToolTip="Första sidan" NextPageToolTip="Nästa sida" PrevPageToolTip="Föregående sida" 
                LastPageToolTip="Sista sidan"></PagerStyle> 
            <NoRecordsTemplate> 
                <div style="text-align: center; line-height: 25px;"
                    <strong>No Users Found!</strong> 
                </div> 
            </NoRecordsTemplate> 
        </MasterTableView> 
        <ClientSettings EnablePostBackOnRowClick="true" Selecting-AllowRowSelect="True"
            <Selecting AllowRowSelect="True" /> 
        </ClientSettings> 
    </telerik:RadGrid> 
</asp:Content> 


using System; 
using System.Web.Security; 
using Telerik.Web.UI; 
 
namespace Adeprimo.Tulo.Web.User.Administration 
    public partial class ManageUsers : System.Web.UI.Page 
    { 
        protected void Page_Load(object sender, EventArgs e) 
        { 
            //Bind dgUsers with all Users 
            rdgUsers.DataSource = Membership.GetAllUsers(); 
            rdgUsers.DataBind(); 
        } 
        #region Add, Update, Delete Member 
        /// <summary> 
        /// Add new member 
        /// </summary> 
        /// <param name="source"></param> 
        /// <param name="e"></param> 
        protected void InsertCommmand(object source, GridCommandEventArgs e) 
        { 
        } 
        /// <summary> 
        /// Update member 
        /// </summary> 
        /// <param name="source"></param> 
        /// <param name="e"></param> 
        protected void UpdateCommand(object source, GridCommandEventArgs e) 
        { 
        } 
 
        /// <summary> 
        /// Delete member 
        /// </summary> 
        /// <param name="source"></param> 
        /// <param name="e"></param> 
        protected void DeleteCommand(object source, GridCommandEventArgs e) 
        { 
            GridEditableItem item = (GridEditableItem)e.Item; 
            Membership.DeleteUser(e.Item.OwnerTableView.Items[e.Item.ItemIndex]["UserName"].Text); 
        } 
        #endregion 
    } 

1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 20 Apr 2010, 12:22 PM
Hello Erik,

Try calling the DataBind() method on the first page load when !Page.IsPostBack and see whether it is working as expected. Checkout the demo for more information about "Simple Data Binding". The better way to bind grid is by using Advanced Databinding by attaching NeedDataSource event.

Hope this information helps you,
Princy.
Tags
Grid
Asked by
Erik Hennerfors
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Share this question
or