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

ImageButton in GridAttachmentColumn

4 Answers 77 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Bernard
Top achievements
Rank 1
Bernard asked on 21 Oct 2010, 03:04 PM
Hello,
I'm using a RadGrid with a GridAttachmentColumn (ButtonType ImageButton) for download.
Everything is Ok and It works well.
But some of the items of my Grid don't have attached file.
So I would like to set the "visible property" of the button to false when there is no attached file.
Is there a way to do that ?
Thanks a lot.
Bernard

4 Answers, 1 is accepted

Sort by
0
Cori
Top achievements
Rank 2
answered on 21 Oct 2010, 04:52 PM
Hello Bernard,

You have to handle the ItemDataBound event and then set the text to blank or clear the controls in that cell, whatever works for yur. Like so:

protected void grdTest_ItemDataBound(object sender, GridItemEventArgs e)
    {
        if (e.Item is GridDataItem)
        {
            GridDataItem grdItem = (GridDataItem)e.Item;
            grdItem.Cells[0].Text = "";
  
            // OR
  
            grdItem.Cells[0].Controls.Clear();
        }
    }

For the Cells collection you need to set it the correct column index for the attachment column.

I hope that helps.
0
Bernard
Top achievements
Rank 1
answered on 22 Oct 2010, 08:47 AM
Hi Cori,

Many thanks for your answer.

I've had already tried this way.
When I inspect the grdItem.Cells[0].Controls, this collection is empty.
and grdItem.Cells[0].Text = "" has no effect.
I thought that It was not the right handler
So I have tried with itemCreated, but no more success...

Regards
Bernard
0
Nikolay Rusev
Telerik team
answered on 26 Oct 2010, 07:37 AM
Hello Bernard,

From Cori's code grdItem has indexer that accepts as parameter column UniqueName. Thus you can use the following:
grdItem["YOUR COLUMN UniqueName"] - this will return the cell for that column in the current data item.

Regards,
Nikolay
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Bernard
Top achievements
Rank 1
answered on 26 Oct 2010, 08:18 AM

 

Hello Nikolay, Hello Cori,

Thanks you for your insistence ! It's works !
It's all my fault !
When I built the GridAttachmentColumn, I set "DataTextField property" to "boo0" and the "UniqueName property" to "AttachmentColumn" (copy/paste from an example...)
And then when I asked grdItem["boo0"], there were nothing !
So I have deleted "UniqueName property" so It take the value of "DataTextField property" value
.
Silly mistake !

Many Thanks to you both
Bernard

Tags
Grid
Asked by
Bernard
Top achievements
Rank 1
Answers by
Cori
Top achievements
Rank 2
Bernard
Top achievements
Rank 1
Nikolay Rusev
Telerik team
Share this question
or