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

[Solved] GridViewDataColumn.CellTemplate at code behind

2 Answers 269 Views
GridView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
pv Upendran
Top achievements
Rank 1
pv Upendran asked on 05 Oct 2009, 12:07 PM
Hi ,
    I am using Gridview in my application.I had apply the data template as following

  <telerikGrid:GridViewDataColumn HeaderText="Delete"  Width="80" IsReadOnly="True">
                    <telerikGrid:GridViewDataColumn.CellTemplate>
                        <DataTemplate>
                            <Image x:Name="imgDelete" Stretch="None" MouseLeftButtonUp="Delete_Click"  Cursor="Hand" Source="../Images/Delete.PNG"/>
                        </DataTemplate>
                    </telerikGrid:GridViewDataColumn.CellTemplate>
                </telerikGrid:GridViewDataColumn>

Here i want to replace the image to Blank or remove the image from the particular cell dynamically at code behind. 


 private void rgvCustName_RowLoaded(object sender, Telerik.Windows.Controls.GridView.RowLoadedEventArgs e)
        {
e.Row.Cells[0].Template =???
}

Can any body help me to create Template or removing image of particular ?

Thanks and regards,

Upendran. P.V.


2 Answers, 1 is accepted

Sort by
0
Vlad
Telerik team
answered on 06 Oct 2009, 06:38 AM
Hello,

You can use Loaded event of this image to achieve your goal easily. Here is an example:

       private void imgDelete_Loaded(object sender, RoutedEventArgs e)
        {
            var item = ((Image) sender).DataContext;
            // cast DataContext to your object type

            if (YourCondition)
            {
                ((Image) sender).Visibility = Visibility.Collapsed;
            }
            else
            {
                ((Image) sender).Visibility = Visibility.Visible;
            }
        }


Sincerely yours,
Vlad
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Hristo
Telerik team
answered on 06 Oct 2009, 10:39 AM
Hi pv Upendran,

You cannot change the Image. Instead you can bind its Source property to some property of your data item. So if the property that you are bound to has value then you will show picture. Else you would not.

I hope this will help you.

Regards,
Hristo
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
GridView
Asked by
pv Upendran
Top achievements
Rank 1
Answers by
Vlad
Telerik team
Hristo
Telerik team
Share this question
or