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

Disable/Enable GridTemplateColumn Controls Based on RowIndex

1 Answer 147 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Colin Mulcahy
Top achievements
Rank 1
Colin Mulcahy asked on 03 Nov 2008, 11:33 PM
Hi,

I have a grid with the folllowing gridTemplateColumn:

<telerik:GridTemplateColumn UniqueName="MoveCol" HeaderStyle-Width="40px">  
    <ItemTemplate> 
        <asp:ImageButton ID="cmdMoveUp" runat="server"></asp:ImageButton> 
        <asp:ImageButton ID="cmdMoveDown" runat="server"></asp:ImageButton> 
    </ItemTemplate> 
</telerik:GridTemplateColumn> 

Need to find out how to do the following:

1). Disable both buttons if grid rowcount is less than 2.
2). Enable and disable both buttons based on the grid total rowcount and not page row count.
3). For cmdMoveUp how do get the grid rowindex to make sure its greate than 0 ?
4). For cmdMoveDown how do I get the grid rowcount to evaluate if grid rowindex is less than it?

5). Can you please clarify the difference between using 

ItemCreated and ItemDataBound events and which is the appropriate event for manipuating values of template controls such as the above.

Thanks,

Colin

1 Answer, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 04 Nov 2008, 04:44 AM
Hi Colin,

Try accessing the entire row count in the ItemEvent of RadGrid as shown below.

CS:
 protected void RadGrid1_ItemEvent(object sender, GridItemEventArgs e) 
    { 
        if (e.EventInfo is GridInitializePagerItem) 
        { 
            int allRowsCount = (e.EventInfo as GridInitializePagerItem).PagingManager.DataSourceCount; 
            if (allRowsCount < 2
            { 
                foreach (GridDataItem item in RadGrid1.MasterTableView.Items) 
                { 
                    ImageButton imgBtn1 = (ImageButton)item["MoveCol"].FindControl("cmdMoveUp"); 
                    ImageButton imgBtn2 = (ImageButton)item["MoveCol"].FindControl("cmdMoveDown"); 
                    imgBtn1.Enabled = false
                    imgBtn2.Enabled = false
                } 
            } 
 
        } 
    } 

You can also refer the following KB article to understand the major differences between ItemCreated and ItemDataBound events.
Distinguishing the major differences between the ItemCreated and ItemDataBound server events

Regards
Shinu.

Tags
Grid
Asked by
Colin Mulcahy
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Share this question
or