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

[Solved] Radgrid databind issue

1 Answer 143 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Ayesha
Top achievements
Rank 1
Ayesha asked on 20 Jul 2009, 03:04 AM
Hi,

I've a radgrid to which i bind my data.  I need to select multiple rows or can select one row and delete them(i have a delete button which does this.)
On\ce i delete the row or rows from radgrid, i again load the grid (have dattacolumn and assign datasource and databind it). 

my problem is if i select one row and click on delete, it works fine. deletes the rows and again binds the grid.

But if i select multiple rows and delete them , it gives me an error telling column name"NAme" already assigned. how do i overcome this. what needs to be donne.
Any help to this would be really appreciated.
Thanks,
ZR

1 Answer, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 21 Jul 2009, 10:06 AM
Hi Zaheka,

You can set the CommandName for the delete button so that you can check for the CommandName in ItemCommand event of RadGrid, then you can loop through the selected items and create the SQL query to delete the row. Here is a example where I used SqlDataSouce to delete the row.

C#:
 
protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e) 
    if(e.CommandName == "DeleteSelected"
    { 
        foreach (GridDataItem selectedItem in RadGrid1.SelectedItems) 
        { 
            String keyValue = selectedItem.GetDataKeyValue("CustomerID").ToString(); // Set the DataKeyName as CustomerID 
            SqlDataSource1.DeleteCommand = String.Format("Delete * from Customers WHERE CustomerID='{0}'", keyValue); // Create the DeleteCommand 
            SqlDataSource1.Delete();                
        } 
    } 
    RadGrid1.Rebind(); 
Hope this would provde some insight to the issue.

-Shinu.
Tags
Grid
Asked by
Ayesha
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Share this question
or