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

RadGrid Edit, update, delete

9 Answers 133 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Carlos
Top achievements
Rank 1
Carlos asked on 05 Sep 2013, 02:38 PM
Hi all, so my problem is, because i havea full auto grid,i cant be manual:

 - How to use the delete option on the radgrid, ans make it call a prompt window.

Best Regards and Thanks

9 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 1
answered on 06 Sep 2013, 03:41 AM
Hi Carlos,

I guess you want to show the confirmation box on the click of Delete button.Please try the following code snippet.

ASPX:
<telerik:GridButtonColumn ConfirmText="Delete this product?" ConfirmDialogType="RadWindow" ConfirmTitle="Delete" ButtonType="ImageButton" CommandName="Delete" Text="Delete"  UniqueName="DeleteColumn">
    <ItemStyle HorizontalAlign="Center" CssClass="MyImageButton"></ItemStyle>
</telerik:GridButtonColumn>

Thanks,
Princy
0
Carlos
Top achievements
Rank 1
answered on 06 Sep 2013, 10:28 AM
Thanks,

but were does that code go,

i remember that i have a automated columns creation.

Best regards
0
Accepted
Princy
Top achievements
Rank 1
answered on 09 Sep 2013, 02:55 AM
Hi Carlos,

Please add the code inside the Columns of the MasterTableView as shown below.

ASPX:
<telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="true" >
    <MasterTableView >
        <Columns>      
            <telerik:GridButtonColumn ConfirmText="Delete this product?" ConfirmDialogType="RadWindow"
                ConfirmTitle="Delete" ButtonType="ImageButton" CommandName="Delete" Text="Delete"
                UniqueName="DeleteColumn">
                <ItemStyle HorizontalAlign="Center" CssClass="MyImageButton"></ItemStyle>
            </telerik:GridButtonColumn>
        </Columns>
    </MasterTableView>
</telerik:RadGrid>

Thanks,
Princy
0
Carlos
Top achievements
Rank 1
answered on 09 Sep 2013, 09:18 AM
Thanks for the answer,

But that will generate a nem column with a button what i want is use the radgrid button option.

Best Regards
0
Princy
Top achievements
Rank 1
answered on 10 Sep 2013, 04:12 AM
Hi Carlos,

I guess you are using AutoGenerateDeleteColumn="true" and to add confirmation to it,please try the following code snippet.

C#:
protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
   {
       if (e.Item is GridDataItem)
       {
           GridDataItem item = (GridDataItem)e.Item;
           LinkButton lnkBtnDelete = (LinkButton)item["AutoGeneratedDeleteColumn"].Controls[0];
           lnkBtnDelete.Attributes["onclick"] = "javascript:return confirm(\'Do you want to delete this item?\')";
       }
   }

Thanks,
Princy
0
Carlos
Top achievements
Rank 1
answered on 12 Sep 2013, 10:27 AM
Hi all,

So now i havea new problem, how do i acess the fields on the add record on a editform?? Remember i have autogenerated columns.

Best Regards
0
Princy
Top achievements
Rank 1
answered on 13 Sep 2013, 05:43 AM
Hi Carlos,

I'm not clear about your requirement,If you want to access the Grid in Insert Mode please try the following code snippet.

C#:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
  {
      if (e.Item is GridEditFormInsertItem || e.Item is GridDataInsertItem) //Check if in InsertMode
      {
         //Your Code 
      }
  }

OR if you want to access the form in Insert Mode in InsertCommand,Please try the following.

When you set the AutoGenerateColumns property of RadGrid to true, the RadGrid control generates a separate column for each data field in the control's assigned datasource. Based on the datatype of the field, the control will generate:

  • GridBoundColumn for string fields

  • GridCheckBoxColumn for boolean fields

  • GridDateTimeColumn for datetime fields

  • GridNumericColumn for numeric fields


C#:
protected void RadGrid1_InsertCommand(object sender, GridCommandEventArgs e)
    {
        if (e.Item is GridEditableItem)
        {
            GridEditableItem insertitem = e.Item as GridEditableItem;
            foreach (GridColumn col in RadGrid1.MasterTableView.AutoGeneratedColumns)
            {
                if (col.DataType == typeof(int))
                {
                    RadNumericTextBox numtxt = (RadNumericTextBox)insertitem[col.UniqueName].Controls[0]; //Accessing the textbox in insertmode
                    string id = numtxt.Text; // Get the values of the Numeric column                  
                }
                //Similarly check for other Data Types
            }
        }
    }

Thanks,
Princy
0
Carlos
Top achievements
Rank 1
answered on 13 Sep 2013, 09:25 AM
Hi all,

Tanks but that works fine in a autogeneratedcolumns = False, my columns are Autogenerated.

Best Regards
0
Accepted
Eyup
Telerik team
answered on 17 Sep 2013, 08:17 AM
Hello Carlos,

You can refer to the following article for accessing the generated controls in edit mode:
( Section Accessing controls in edit/insert mode )
http://www.telerik.com/help/aspnet-ajax/grid-accessing-cells-and-rows.html

Hope this helps.

Regards,
Eyup
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
Tags
Grid
Asked by
Carlos
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 1
Carlos
Top achievements
Rank 1
Eyup
Telerik team
Share this question
or