add delete button to each row in radgrid

17 posts, 0 answers
  1. Kugi
    Kugi avatar
    8 posts
    Member since:
    Jan 2012

    Posted 30 Jan 2012 Link to this post

    Hi, I really love radcontrols although i'm still using a trial version of asp.net ajax. I can't figure out how I can put imagebuttons on every row I have on my radgrid. These buttons will try to get the value of each row's "Name" field. I tried adding a gridbuttoncolumn but i can't add a handler to it and I don't know how to do it. Please help me. I'm in an urgent need.Thanks :)
  2. RvdGrint
    RvdGrint avatar
    112 posts
    Member since:
    May 2011

    Posted 30 Jan 2012 Link to this post

    Kugi,

    In the columns section of the RadGrid you should add the following column:
    <telerik:GridButtonColumn ButtonType="ImageButton" CommandName="Delete"
        FilterControlAltText="Filter DeleteColumn column"
        ImageUrl="~/Images/RadGrid/16pxDelete.png" Text="Delete"
        UniqueName="DeleteColumn" Resizable="false" ConfirmText="Delete record?">
        <HeaderStyle CssClass="rgHeader ButtonColumnHeader"></HeaderStyle>
        <ItemStyle CssClass="ButtonColumn" />
    </telerik:GridButtonColumn>

    You can handle the delete action from the ItemCommand event in the code-behind.

    Regards,
      Jos
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Jayesh Goyani
    Jayesh Goyani avatar
    2732 posts
    Member since:
    May 2010

    Posted 30 Jan 2012 Link to this post

    Hello,

    <MasterTableView DataKeyNames="ID" Name="Parent" HierarchyLoadMode="Client">
                  <Columns>
                      <telerik:GridButtonColumn ButtonType="ImageButton" CommandName="Delete" FilterControlAltText="Filter DeleteColumn column"
                          ImageUrl="~/Images/RadGrid/16pxDelete.png" Text="Delete" UniqueName="DeleteColumn"
                          Resizable="false" ConfirmText="Delete record?">
                          <HeaderStyle CssClass="rgHeader ButtonColumnHeader"></HeaderStyle>
                          <ItemStyle CssClass="ButtonColumn" />
                      </telerik:GridButtonColumn>
                      <telerik:GridBoundColumn DataField="Name" UniqueName="Name">
                      </telerik:GridBoundColumn>
    protected void RadGrid1_DeleteCommand(object sender, GridCommandEventArgs e)
        {
            GridDataItem item = e.Item as GridDataItem;
     
            // using columnuniquename
            string str1 = item["Name"].Text;
                  
            // using DataKey
            string str2 = item.GetDataKeyValue("ID").ToString();
    }

    or

    <MasterTableView DataKeyNames="ID" Name="Parent" HierarchyLoadMode="Client">
                  <Columns>
                      <telerik:GridTemplateColumn>
                          <ItemTemplate>
                              <asp:Button ID="Button1" runat="server" Text="Delete" CommandName="Delete" />
                          </ItemTemplate>
                      </telerik:GridTemplateColumn>
                      <telerik:GridBoundColumn DataField="Name" UniqueName="Name">
                      </telerik:GridBoundColumn>



    Thanks,
    Jayesh Goyani
  5. Kugi
    Kugi avatar
    8 posts
    Member since:
    Jan 2012

    Posted 30 Jan 2012 Link to this post

    Thanks for the quick replies.I tried the one jayesh gave,it almost worked but it seems the event wasn't handled.Am i suppose to add RadGrid1_DeleteCommand as eventhandler to something?
  6. Kugi
    Kugi avatar
    8 posts
    Member since:
    Jan 2012

    Posted 30 Jan 2012 Link to this post

    Nevermind, i added 'Handles gridsummary.DeleteCommand' and it worked. But there's still a problem,though I think could be on the other parts of my program. The first time i click the delete button,a dialog appears and if I click Ok it doesn't pass through RadGrid1_DeleteCommand (i have a break point there).Then  click it again and no dialog will appear but it will now pass through the eventhandler....so what was that? LOL
    Anyway, I want to make the confirm dialog better. I put 'ConfirmDialogType="RadWindow" ConfirmTitle=""' on the source but both wasn't reflected. The dialog that appeared is still normal and with 'loclhost...blah blah" on its title bar.

    sorry for my long post,thank you very much. much appreciated :)
  7. Jayesh Goyani
    Jayesh Goyani avatar
    2732 posts
    Member since:
    May 2010

    Posted 30 Jan 2012 Link to this post

    Hello,

      <telerik:RadScriptManager ID="RadScriptManager1" runat="server">
            </telerik:RadScriptManager>
            <telerik:RadWindowManager ID="RadWindowManager1" runat="server"></telerik:RadWindowManager>
     
            <telerik:RadGrid ID="RadGrid1" runat="server" OnNeedDataSource="RadGrid1_NeedDataSource"
    >
                <MasterTableView>
                    <Columns>
                        <telerik:GridButtonColumn ButtonType="ImageButton" CommandName="Delete" FilterControlAltText="Filter DeleteColumn column"
                             Text="Delete" UniqueName="DeleteColumn" ConfirmDialogType="RadWindow"
                            Resizable="false" ConfirmText="Delete record?">
                             
                        </telerik:GridButtonColumn>

    Please add WindowManager in your page.

    Thanks,
    Jayesh Goyani
  8. Kugi
    Kugi avatar
    8 posts
    Member since:
    Jan 2012

    Posted 30 Jan 2012 Link to this post

    wow thanks it worked. But I still have the problem. I have to click the delete button twice before it execute radgrid_deletecommand :(
  9. Jayesh Goyani
    Jayesh Goyani avatar
    2732 posts
    Member since:
    May 2010

    Posted 30 Jan 2012 Link to this post

    Hello,


    Which method you used for binding the data to RadGrid ?

    Note : please use Advance data binding  method for binding the grid data.


    Thanks,
    Jayesh Goyani
  10. Kugi
    Kugi avatar
    8 posts
    Member since:
    Jan 2012

    Posted 30 Jan 2012 Link to this post

    I added rows in a datatable and bind it with radgrid. I don't know any other way. Sorry I'm a beginner with these things.
  11. Jayesh Goyani
    Jayesh Goyani avatar
    2732 posts
    Member since:
    May 2010

    Posted 30 Jan 2012 Link to this post

    Hello,

    Are you binding the data in "NeedDataSource" event or not ??

    OR

    your C# code should be

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using Telerik.Web.UI;
    using System.Data;
     
    public partial class testaspnet : System.Web.UI.Page
    {
     
        protected void Page_Load(object sender, EventArgs e)
        {
        }
     
    protected void RadGrid1_NeedDataSource(object sender, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
        {
     
            dynamic data = new[] {
                    new { ID = "1", Name ="Name11",ParentID = "0"},
                    new { ID = "2", Name ="Name11",ParentID = "1"},
                    new { ID = "3", Name ="Name11",ParentID = "2"},
                    new { ID = "4", Name ="Name1",ParentID = "3"}
                };
     
            RadGrid1.DataSource = data;
     
        }
     
      protected void RadGrid1_DeleteCommand(object sender, GridCommandEventArgs e)
        {
    }
     
     
    }


    Thanks,
    Jayesh Goyani
  12. Kugi
    Kugi avatar
    8 posts
    Member since:
    Jan 2012

    Posted 30 Jan 2012 Link to this post

    Thank you very much! I fixed it by setting enableviewstate of the radgrid to false. Sorry I didn't really followed the advance databinding although I got the idea from your link. Whatever it is, I achieved what I want to happen. Thanks again :)
  13. bharath
    bharath avatar
    23 posts
    Member since:
    Jun 2011

    Posted 06 May 2014 in reply to Jayesh Goyani Link to this post

    HI  ayesh i want to do add newrecord , Edit , delete of Rows for radgrid which is created dynamically.
    i want to do it inline method.


    /Bharath
  14. bharath
    bharath avatar
    23 posts
    Member since:
    Jun 2011

    Posted 06 May 2014 in reply to Jayesh Goyani Link to this post

    HI  Jayesh i want to do add newrecord , Edit , delete of Rows for radgrid which is created dynamically.
    i want to do it inline method.
  15. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 07 May 2014 in reply to bharath Link to this post

    Hi Bharath,

    I'm not clear about your requirement, I guess you want to set the Edit, Delete and AddNewRecord button dynamically. Please take a look at the below code snippet, if this doesn't help elaborate on your requirement.

    C#:
    protected void Page_Init(object source, System.EventArgs e)
    {
        RadGrid1 = new RadGrid();
       //To have AddNewRecord
        RadGrid1.MasterTableView.CommandItemDisplay = GridCommandItemDisplay.Top;
        //To have Inline EditMode
        RadGrid1.AutoGenerateEditColumn = true;
        RadGrid1.MasterTableView.EditMode = GridEditMode.InPlace; 
        //To have Delete
        RadGrid1.AutoGenerateDeleteColumn = true;
             // OR
        //If you want ImageButton you can use this instead of AutoGenerateEditColumn
        GridEditCommandColumn editColumn = new GridEditCommandColumn();
        editColumn.ButtonType = GridButtonColumnType.ImageButton;
        editColumn.UniqueName = "EditColumn";
        RadGrid1.MasterTableView.Columns.Add(editColumn);
     
        //Similary for delete button
        GridButtonColumn deleteColumn = new GridButtonColumn();
        deleteColumn.ButtonType = GridButtonColumnType.ImageButton;
        deleteColumn.CommandName = RadGrid.DeleteCommandName;
        deleteColumn.UniqueName = "DeleteColumn";
        RadGrid1.MasterTableView.Columns.Add(deleteColumn);
    }

    Thanks,
    Shinu
  16. bharath
    bharath avatar
    23 posts
    Member since:
    Jun 2011

    Posted 09 Sep 2014 in reply to Jayesh Goyani Link to this post

    hi,
      i want to add textbox (dynamic) to one column of radgrid and make that text as autocomplete extender.

      i added textbox and autocompleteextender control in _itemDatabound method.but when executed i got the error 
     autocompleteextender.TargetControlId  with that textbox id is not found.

    when the same textbox i added to the page (page.controls.Add(txt))  error is not coming but inside radgrid textbox is not working as 
    autocomplete Extender. Out side text box is working as autocompleteextender.




  17. bharath
    bharath avatar
    23 posts
    Member since:
    Jun 2011

    Posted 09 Sep 2014 in reply to Shinu Link to this post

    hi,
      i want to add textbox (dynamic) to one column of radgrid and make that text as autocomplete extender.

      i added textbox and autocompleteextender control in _itemDatabound method.but when executed i got the error 
     autocompleteextender.TargetControlId  with that textbox id is not found.

    when the same textbox i added to the page (page.controls.Add(txt))  error is not coming but inside radgrid textbox is not working as 
    autocomplete Extender. Out side text box is working as autocompleteextender.
  18. Angel Petrov
    Admin
    Angel Petrov avatar
    1007 posts

    Posted 12 Sep 2014 Link to this post

    Hi Bharath,

    The behavior experienced may be expected. The OnItemDataBound event is fired too later for adding controls programmatically. Please try moving the logic in the OnItemCreated event and test whether this resolves the problem. If it does not please share with us the markup and code-behind of the page so we could examine the exact implementation.

    Regards,
    Angel Petrov
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017