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

how to trap selected item in cancel command??

2 Answers 58 Views
Grid
This is a migrated thread and some comments may be shown as answers.
mac
Top achievements
Rank 1
mac asked on 01 Oct 2008, 04:12 PM

Update ---
figured it out.
Slap this into the DeleteCommand... 

Dim
ID As String = e.Item.OwnerTableView.DataKeyValues(e.Item.ItemIndex)
(
"Your Data Key Name").ToString()
---End Update

well it is face slap wednesday and I am confused.
all i want to do is have 2 columns. cancel (link button) and select (link button)
I can trap the selected value (datakeyname) using the selectedindex.. but cannot for the life of me see how to get it when i use the cancel command. I can return 'cancelled' in the msglabel... however I cannot get the value of the row that I need to work with.

source

 <telerik:RadGrid  ID="RadGrid1" width="200px"  runat="server" GridLines="None">  
   <MasterTableView DataKeyNames="Pos_id">  
   <Columns> 
<telerik:GridButtonColumn CommandName="Delete"  ButtonType="LinkButton" Text="Cancel" UniqueName="CancelCol" /> 
 <telerik:GridButtonColumn  CommandName="Select" DataTextField="ListName" UniqueName="column1" /> 
     </Columns> 
        <RowIndicatorColumn> 
            <HeaderStyle Width="20px" /> 
        </RowIndicatorColumn> 
        <ExpandCollapseColumn> 
            <HeaderStyle Width="20px" /> 
        </ExpandCollapseColumn> 
     
   </MasterTableView> 
   <ClientSettings> 
   <Selecting AllowRowSelect="True" /> 
   </ClientSettings> 
                    </telerik:RadGrid> 

Code:

 
    Protected Sub RadGrid1_DeleteCommand(ByVal source As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles RadGrid1.DeleteCommand  
        Try  
            'Run a SQLNonQry to update data  
            'repopulate  
            msglabel.Text = RadGrid1.SelectedValue & " Cancelled "  
            populateGrid()  
        Catch ex As Exception  
            msglabel.Text = ex.Message  
        End Try  
    End Sub  
 
    Protected Sub RadGrid1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles RadGrid1.SelectedIndexChanged  
        'update related ascx form  
        Ctrls_frm_CreatePosting.posid = RadGrid1.SelectedValue  
        msglabel.Text = RadGrid1.SelectedValue & " Selected"  
 
    End Sub  
 
sub PopulateGrid()  
'basic grid populate with sql ds  
end sub  
 

2 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 03 Oct 2008, 05:46 AM
Hello Mac,

Try out the following code to get the DataKeyValue for a particular row when the cancel button for that row is clicked.
cs:
   protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e) 
    { 
        if (e.CommandName == "Delete") 
        { 
            string strTxt = (e.Item as GridDataItem).GetDataKeyValue("KeyName").ToString(); 
        } 
    } 

Thanks
Princy.
0
mac
Top achievements
Rank 1
answered on 03 Oct 2008, 04:07 PM
does it matter which column type you are using in the sample you provided above? ie.. clientdeletecolumn vs. clientselect vs. template with standard asp:button?
i was not able to hook into the itemcommand on any of these for some reason.
mac
Tags
Grid
Asked by
mac
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
mac
Top achievements
Rank 1
Share this question
or