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

EditFormTemplate

3 Answers 60 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Rajiv
Top achievements
Rank 1
Rajiv asked on 12 Mar 2009, 05:08 AM
Hello,

I have a Radgrid control on a webpage where I have defined EditFormType="Template" for the MasterTableView. There are few controls in this template for which I want to set the visibility to false depending on some conditions. I can set the visiblility of these controls to false in ItemDataBound Event but in these case the datasource associated with the control is still executed. i.e. even though the control is invisible the stored procedure associated with that control is still executed.
 
How can I set the control in the edit form to invisisble and not have the datasource associated with that control to be executed.

Please help.

Thanks,
Rajiv

3 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 12 Mar 2009, 07:31 AM
Hello Rajiv,

You can possibly bind the control to the datasource, once it is made visible rather than preventing the control from binding when its invisible.

Thanks
Princy.
0
Rajiv
Top achievements
Rank 1
answered on 12 Mar 2009, 08:11 AM
Thank you for the Reply, Princy.

The problem is that I am declaratively binding the control to the datasource using SQLdatasource, so I am not sure If I can do this.

Thanks,
Rajiv
0
Accepted
Shinu
Top achievements
Rank 2
answered on 13 Mar 2009, 06:14 AM
Hi Rajiv,

As Princy suggested, one way is to bind the grid based on a condition,  in the code behind rather than declaratively setting the DataSource for the grid as shown below:
RadGrid1.DataSourceID = "SqlDataSource1";     

Another way is to cancel the selecting event of the SqlDataSource based on a condition as shown below:
cs:
 protected void SqlDataSource1_Selecting(object sender, SqlDataSourceSelectingEventArgs e)  
    {  
        foreach (GridEditFormItem editedItem in RadGrid1.MasterTableView.GetItems(GridItemType.EditFormItem))  
        {  
            GridDataItem item = (GridDataItem)editedItem.ParentItem;  
            if (item["CustomerID"].Text == "ALFKI")  
               e.Cancel = true;  
            else 
                e.Cancel = false;  
        }  
    }  

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