Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Apr 25th, 2012  |  syntax: None  |  size: 2.50 KB  |  hits: 94  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Get ID of the Control which fires ItemCommand in RadGrid
  2. <telerik:RadGrid ID="RGStyleGuideRestrictions" runat="server" DataSourceID="SqlDataSource1"
  3.                 OnItemCommand="RGStyleGuideRestrictions_ItemCommand"
  4.  
  5.     <MasterTableView DataSourceID="SqlDataSource1" DataKeyNames="TerritoryReportGroup">
  6.  
  7.       <Columns>
  8.         <telerik:GridTemplateColumn UniqueName="TemplateColumn">
  9.             <ItemTemplate>                
  10.                 <asp:ImageButton ID="imgBtn1" runat = "server"/>
  11.                 <asp:ImageButton ID="imgBtn2" runat = "server"/>                    
  12.             </ItemTemplate>
  13.         </telerik:GridTemplateColumn>
  14.       </Columns>
  15.     </MasterTableView>
  16. </telerik:RadGrid>
  17.        
  18. protected void RGStyleGuideRestrictions_ItemCommand(object source, GridCommandEventArgs e)
  19. {
  20.    ImageButton imgBtn1 = e.item.FindControl("imgBtn1") as ImageButton;
  21.    ImageButton imgBtn2 = e.item.FindControl("imgBtn2") as ImageButton;
  22. }
  23.        
  24. <asp:ImageButton ID="imgBtn1" runat = "server" CommandName="imgAction1"/>
  25.  <asp:ImageButton ID="imgBtn2" runat = "server" CommandName="imgAction2"/>
  26.        
  27. protected void RGStyleGuideRestrictions_ItemCommand(object source, GridCommandEventArgs e)
  28.  {
  29.       switch(e.CommandName)
  30.       {
  31.          case "imgAction1": // do stuff here
  32.              break;
  33.          case "imgAction2": // do some other stuff here
  34.              break;
  35.       }
  36.  }
  37.        
  38. protected void RGStyleGuideRestrictions_ItemCommand(object source, GridCommandEventArgs e)
  39. {
  40.    ImageButton fired = source as ImageButton;
  41.    if(fired!=null && fired.Id=="imgBtn1")
  42.    {
  43.       //imgBtn1 fired the command
  44.    }
  45.    else
  46.    {
  47.      // and so on...
  48.    }
  49.    ImageButton imgBtn1 = e.item.FindControl("imgBtn1") as ImageButton;
  50.    ImageButton imgBtn2 = e.item.FindControl("imgBtn2") as ImageButton;
  51. }
  52.        
  53. <telerik:GridTemplateColumn UniqueName="TemplateColumn">
  54.         <ItemTemplate>                
  55.             <asp:ImageButton CommandArgument="btn1" ID="imgBtn1" runat = "server"/>
  56.             <asp:ImageButton CommandArgument="btn2" ID="imgBtn2" runat = "server"/>                    
  57.         </ItemTemplate>
  58.     </telerik:GridTemplateColumn>
  59.  
  60.  
  61. protected void RGStyleGuideRestrictions_ItemCommand(object source, GridCommandEventArgs e)
  62. {
  63.  
  64.    if(e.CommandArgument=="btn1")
  65.    {
  66.       //imgBtn1 fired the command
  67.    }
  68.    else if(e.CommandArgument=="btn2")
  69.    {
  70.       //imgBtn2 fired the command  
  71.    }
  72.    ImageButton imgBtn1 = e.item.FindControl("imgBtn1") as ImageButton;
  73.    ImageButton imgBtn2 = e.item.FindControl("imgBtn2") as ImageButton;
  74. }