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

problem deleting rows

7 Answers 178 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Daniel
Top achievements
Rank 1
Daniel asked on 04 Aug 2008, 09:55 PM
Hi all,

I am having some troubles when i try to delete rows in my grid. I populate it with personalized objects and when i´m going to delete a row I need to call a procedure  and assign a param.

1) In the declaration of the grid i have:
AutoGenerateDeleteColumn="true" 
OnItemCommand="RadGrid1_ItemCommand"
OnDeleteCommand="RadGrid1_DeleteCommand">

2) In my commandItemTemplate i use:       
<asp:LinkButton ID="lnkDelete" 
OnClientClick="javascript:return confirm('confirmation message?')"
runat="server" CommandName="DeleteSelected"
CausesValidation="false"> Delete Selected
</asp:LinkButton>

3) I  have a gridClientSelectColumn to select the registers i want to delete

<telerik:GridClientSelectColumn UniqueName="select" HeaderStyle-Width="40px" />


____________________
So the grid has on the top a linkbutton to delete registers and 2 columns one for select and other for delete (i have more, but right know i'm focus on these).

* I have the event in the cs to delete the row and the register when the user clicked the delete cell (for the row), but the text for the column is always 'delete' and i want other name for the language ... this is posibble??? ... also i need that before excecute the event it needs to open a confirmation box (like the link button on the top of the grid)

** I can select registers and mark them on the checkbox column and when i clicked the deleteRegisters linkButton it open the confirm Box, but if i clicked 'ok'
it goes to the RadGrid1_ItemCommand event but i cant take the items to delete them (RadGrid1.SelectedItems returns 0 items)...


please help me it is really important ... and thanks a lot for all

7 Answers, 1 is accepted

Sort by
0
Veli
Telerik team
answered on 05 Aug 2008, 09:29 AM
Hello Daniel,

You can define your own GridTemplateColumn with a button in the ItemTemplate to attach a confirm dialog to its client click event. And you can also modify its Text and column's HeaderText properties for localization:

<telerik:GridTemplateColumn HeaderText="Custom delete text"
    <ItemTemplate> 
        <asp:LinkButton ID="DeleteButton" runat="server" Text="Custom delete text" 
            CommandName="Delete" OnClientClick="javascript:return confirm('confirmation message?')"
        </asp:LinkButton> 
    </ItemTemplate> 
</telerik:GridTemplateColumn> 


All the best,
Veli
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Daniel
Top achievements
Rank 1
answered on 05 Aug 2008, 02:48 PM
Veli,

Thx for the post, i tried that solution few days ago but it didnt worked because i forget the CommandName for the linkbutton :P. But it is working perfect right now.

But how can i fix the problem of deleting the selected rows? .. i select them with my gridClientSelectColumn and when i pressed the delete LinkButton (placed on the CommandItemTemplate) it doesnt works ... it shows the confirmation dialog, but it doesn delete anything.

Like i said in the last post  In my commandItemTemplate i use:       
<asp:LinkButton ID="lnkDelete" 

OnClientClick="javascript:return confirm('confirmation message?')"

runat="server" CommandName="DeleteSelected"

CausesValidation="false"> Delete Selected

</asp:LinkButton>

i also change he commandName for the same of the templateColumn but nothing and in the codebehing i have the        

protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e)

and catch the event when the commandName.equals("DeleteSelected")... but it said that the grid does not have selected rows .... why is that??

Thanks again and i hope you can help me with this ... thx again


0
Veli
Telerik team
answered on 06 Aug 2008, 09:19 AM
Hi daniel,

Could you, please provide some sample code from your DeleteCommand handler and RadGrid's markup relevant to deleting an item. I think the problem you are having is more concerned with the way RadGrid is configured for deleting items, rather than the setup of the delete button.

Sincerely yours,
Veli
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Daniel
Top achievements
Rank 1
answered on 06 Aug 2008, 02:32 PM
Hi Veli, thx or the post...

Here is the code i have in the class:

DeleteCommand:
//This event works fine to delete an specific row
protected void RadGrid1_DeleteCommand(object source, GridCommandEventArgs e)
{
try
   {
      ArtistMailingListUserSTL mailingList = (ArtistMailingListUserSTL)e.Item.DataItem;
     
//this function deletes the specific row (use the id)
AdministrationBLL.ArtistMailingListUserDelete(mailingList);

// here i reload the grid and verify new changes
      ArtistSTL artista = new ArtistSTL();
      artistMailingList = AdministrationBLL.ArtistMailingListUserGetAll(new ArtistMailingListUserSTL(), artista);
      RadGrid1.DataSource = artistMailingList;
      RadGrid1.DataBind();
   }
   catch (Exception ex) {
    ;
   }
}

// this is the event i supossed i need to delete the selected rows
protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e)
{
try
{
switch (e.CommandName) {
case "DeleteSelected":

//when I click the delete all rows it goes here,
//but it sais that any row is selected
Object arts=RadGrid1.SelectedItems;
break;
default:
string x = e.CommandName.ToString();
break;
}
}
catch (Exception ex){;}
}

::::::::::::::::::::::::::::::::::
Here is the code i have in the aspx:

Definition in the grid:

<telerik:RadGrid ID="RadGrid1" runat="server" Width="97%" PageSize="12" 
AllowMultiRowSelection="true"
AllowMultiRowEdit="false"
AllowFilteringByColumn="True"
EnableAjaxSkinRendering="true"
AllowPaging="True"
AllowSorting="true"
AutoGenerateColumns="false"
ShowStatusBar="true"
OnItemCreated="RadGrid1_ItemCreated"
OnItemCommand="RadGrid1_ItemCommand"
OnDeleteCommand="RadGrid1_DeleteCommand">

LinkButton on the commandItemTemplate

<asp:LinkButton ID="lnkDelete" OnClientClick="javascript:return confirm('Desea eliminar todos los registros seleccionados?')"
runat="server"
CommandName="DeleteSelected"
CausesValidation="false">
<img style="border:0px;vertical-align:middle;" alt="" src="Images/Maestras/Delete.gif" /> Delete Selected
</asp:LinkButton>

Veli please try to help me ... thx 4 all

0
Daniel
Telerik team
answered on 11 Aug 2008, 10:41 AM
Hello Daniel,

For your convenience I made a sample website illustrating the desired scenario. You can find it attached to this post. Additionally it would be helpful if you read this help article: API For Controlling the Automatic Operations

Kind Regards,
Daniel
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Daniel
Top achievements
Rank 1
answered on 11 Aug 2008, 09:27 PM
Hi Kind and thx for the post

I can not add the " DeleteCommand="DELETE FROM [Shippers] WHERE [ShipperID] = @ShipperID"  line to my code because i have all the sp in a separate config file, so all my connections and db access are in a diferent place but i use a function that delete rows correctly ...

The main problem i have is that always it sais that i dont have any selected rows, so for the code u send to me in the item command event,
if (e.CommandName == "DeleteSelected")
        {
            if (RadGrid1.SelectedIndexes.Count == 0)
            {
                return;
            }

It always return in the first 'if '. I have a selectColumn and the grid properties (AllowMultiRowSelection, EnableAjaxSkinRenderin, AllowAutomaticsDeletes ) with True. So apparently i can select diferent rows but after i clicked the delete button it always goes to the first if and after that the selected rows become unchecked, but nothing pass.

PLease help me i have done everything but i dont know what i am doing wrong

0
Daniel
Telerik team
answered on 12 Aug 2008, 07:12 AM
Hello Daniel,

Could I ask you to isolate the issue in simple working example and send it to us via a regular support ticket? The behavior you are experiencing should have a logical reason. We will be able to give you straight-to-the-point answer as soon as we receive your code.

Regards,
Daniel
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
Grid
Asked by
Daniel
Top achievements
Rank 1
Answers by
Veli
Telerik team
Daniel
Top achievements
Rank 1
Daniel
Telerik team
Share this question
or