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

[Solved] When row clicked find radgrid column value.

1 Answer 158 Views
Grid
This is a migrated thread and some comments may be shown as answers.
noyan
Top achievements
Rank 1
noyan asked on 02 Apr 2009, 12:50 PM
I have a gridview and when gridview clicked

 

 

protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e)  
        {  
           if (e.CommandName == "RowClick" && e.Item is GridDataItem)  
            {  
                GridEditableItem eeditedItem = e.Item as GridEditableItem;  
               int customerId = Convert.ToInt32(editedItem.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["CustomerId"]);  
            }  
        } 

use the above code block to take CustomerId of selected customer which was written by one of board members. But I have no datakeyvalues because mygridview use needdatasource and advance binding as below

 

 

 

    protected void RadGrid1_NeedDataSource(object source, GridNeedDataSourceEventArgs e)  
    {  
        RadGrid1.DataSource = GetDataTable("SELECT Customerid,CustomerName,CustomerSurname FROM Customers ");  
    }  
 

In shortly, I wonder How can I get Customerid of selected row inside RadGrid1_Itemcommand, moreover, In my trials I see e.Item.ItemIndex give the index of selected rows but because I use some filterings I have no chance to use datatable column property and besides, radgrid has no rows collection to iterate throıgh rows. Pls help me how can I find CustomerId without having DataKeyValues
All helps will be appreciated, thank you in advance.

1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 03 Apr 2009, 05:25 AM
Helo Noyan,

Try out the following code snippet.

CS:
protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e)  
{  
    if (e.CommandName == "RowClick" && e.Item is GridDataItem)  
    {  
        GridDataItem item = (GridDataItem)e.Item;  
        int customerId = Convert.ToInt32(item["CustomerId"].Text);  
    }    

Thanks,
Princy.
Tags
Grid
Asked by
noyan
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Share this question
or