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

Find Control & Enable\Disable at time of loading rad grid

2 Answers 482 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Rahul Singh
Top achievements
Rank 1
Rahul Singh asked on 23 Oct 2009, 11:38 AM
Hi All,

I have a rad grid which has image buttons as item templates. I need to --

Enable or disable these image buttons at time of binding the grid based on some flag from database.

So how to do this and  find these controls from code behind for enabling & disabling.
Also which event i should use for one of these image buttons click inside the item template e.g. hv to capture click event for these buttons.

Thanks in advance

Rahul

2 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 23 Oct 2009, 12:06 PM
Hello Rahul,

You can access the buttons in the ItemCreated of the grid to disable/enables them as shown below:
aspx:
<telerik:GridTemplateColumn HeaderText="TemplateColumn1"  UniqueName="TemplateColumn1">  
    <ItemTemplate>  
        <asp:ImageButton ID="img1" runat="server" CommandName="ButtonClicked" ImageUrl="~/Images/Image1.gif" />  
    </ItemTemplate>  
</telerik:GridTemplateColumn>  
<telerik:GridTemplateColumn HeaderText="TemplateColumn2" UniqueName="TemplateColumn2">  
    <ItemTemplate>  
        <asp:ImageButton ID="img2" runat="server" ImageUrl="~/Images/Image2.gif"  />  
    </ItemTemplate>  
</telerik:GridTemplateColumn>  

c#:
protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e) 
    { 
        if (e.Item is GridDataItem) 
        { 
            GridDataItem item = (GridDataItem)e.Item; 
            ImageButton btn = item.FindControl("img1"as ImageButton; 
            btn.Enabled = false;            
 
        } 
     } 

You can set the CommandName of the button and then check for the command in the ItemCommand which will fire when the button is clicked:
c#:
protected void gridLearningList_ItemCommand1(object source, GridCommandEventArgs e) 
    { 
        if (e.CommandName == "ButtonClicked"
        { 
             
        }  
    } 

Thanks
Princy.
0
Rahul Singh
Top achievements
Rank 1
answered on 26 Oct 2009, 07:40 AM
Hi Princy,

Thax a lot for ur efforts for my post. But i doubt my case is little diferent fromt his where asp image buttons are not used, this u can see from code below :

<rad:GridEditCommandColumn ButtonType="ImageButton" EditImageUrl="../Images/editItem.gif">
    <HeaderStyle Font-Bold="True" Wrap="False" />
    <ItemStyle Wrap="true" />
</rad:GridEditCommandColumn>



So, in this case how click event will be captured ? and also if grid_ItemCreated event is applicable here to enable/disable this image buttons at time of binding the grid..


Thanks

Rahul


Tags
Grid
Asked by
Rahul Singh
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Rahul Singh
Top achievements
Rank 1
Share this question
or