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

Disabling items depending on DataSet entry?

1 Answer 57 Views
Grid
This is a migrated thread and some comments may be shown as answers.
scrut
Top achievements
Rank 1
scrut asked on 05 Jul 2008, 07:25 PM
I have a grid with a GridButtonColumn like this one:

<telerik:GridButtonColumn CommandName="delete" Text="Delete" UniqueName="delete" ConfirmText="Are you sure you want to delete this item?">  
    <HeaderStyle Width="30px" /> 
    <ItemStyle Font-Bold="False" Font-Italic="False" Font-Overline="False" Font-Strikeout="False" Font-Underline="False" ForeColor="#182B45" Wrap="True" /> 
</telerik:GridButtonColumn> 

The DataTable associated with this Grid contains a column "DELETE" which either contains the entry "true" or "false" for each row.

What I now want to do is: the item in the above shown GridButtonColumn should be enabled/visible ONLY if the associated DataTable-entry shows the entry "true" for the row.

So what I apparently need is an iterator over the Grid and over the DataTable doing something like
for each item of datatable
if (dataTable.Item["Delete"].Equals("true") RadGrid1.Item[][].Disabled

How can that be done

1 Answer, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 07 Jul 2008, 05:25 AM
Hi Scrut,

Add a GridBoundColumn and bind it with the DELETE field from the DataTable and try the following code snippet in the ItemDataBound event to enable/disable the Delete button in the GridButtonColumn.

ASPX:
<telerik:GridBoundColumn DataField="Delete" HeaderText="Delete" 
                        UniqueName="Delete"
                    </telerik:GridBoundColumn> 
                     
                    <telerik:GridButtonColumn Text="Delete"  ButtonType="LinkButton"  UniqueName="DeleteCol" ></telerik:GridButtonColumn> 
             

CS:
 protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e) 
    { 
        if (e.Item is GridDataItem) 
        { 
            GridDataItem dataItem = e.Item as GridDataItem; 
            string strTxt = dataItem["Delete"].Text.ToString(); 
            LinkButton lnkbtn = (LinkButton)dataItem["DeleteCol"].Controls[0]; 
            if (strTxt == "False") 
            { 
                lnkbtn.Enabled = false
            } 
            else 
                lnkbtn.Enabled = true
 
        } 
       
    } 


Thanks
Shinu.
Tags
Grid
Asked by
scrut
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Share this question
or