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

Own controls in 1 column

2 Answers 51 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Peter
Top achievements
Rank 1
Peter asked on 04 Oct 2012, 01:11 PM
Hi,

I would like to ask you if there is possible to create column in Grid where I would have several own controls.

In that column there will be 4 small icons, which will have changed visibility according to certain data in given row. Is there any example, how I can make it ?

And I also have one question regarding to checkbox... I need to have checkbox in the column but it won't be bounded to some data. It will be only checkbox which also will be displayed according to data in the row. Because for some rows I will need to hide it. Which column I should use for this one ?

In the attachement there is a screenshot of gridview I would like to achieve with RadGrid.

Sorry for bothering, but I  tried to search the pages for the answer before posting it here... I am really lost...

Thanks for any help

2 Answers, 1 is accepted

Sort by
0
Accepted
Jayesh Goyani
Top achievements
Rank 2
answered on 04 Oct 2012, 01:25 PM
Hello,

protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
    {
        if (e.Item is GridDataItem)
        {
            GridDataItem item = e.Item as GridDataItem;
            CheckBox CheckBox1 = item.FindControl("CheckBox1") as CheckBox;
            Image Image1 = item.FindControl("Image1") as Image;
 
            if (item.GetDataKeyValue("ID").ToString() == "YourComparedValue") // Using Data Key
            {
                if (CheckBox1 != null && Image1 != null)
                {
                    // Set Visibility
                    CheckBox1.Visible = Image1.Visible = false;
                    //OR
                    // Set Style
                    CheckBox1.Style.Add("display","none");
                    Image1.Style.Add("display", "none");
 
                }
            }
 
            //OR
 
            if (item["Name"].Text == "YourComparedValue") // Using Column
            {
                if (CheckBox1 != null && Image1 != null)
                {
                    // Set Visibility
                    CheckBox1.Visible = Image1.Visible = false;
                    //OR
                    // Set Style
                    CheckBox1.Style.Add("display", "none");
                    Image1.Style.Add("display", "none");
 
                }
            }
        }
    }
<MasterTableView DataKeyNames="ID">
                <Columns>
                    <telerik:GridBoundColumn DataField="Name" UniqueName="Name" HeaderText="Name">
                    </telerik:GridBoundColumn>
                    <telerik:GridTemplateColumn UniqueName="Actions">
                        <ItemTemplate>
                            <asp:CheckBox ID="CheckBox1" runat="server" />
                            <br />
                            <asp:Image ID="Image1" runat="server" ImageUrl="~/images/jayesh-Softweb.jpg" />
                        </ItemTemplate>
                    </telerik:GridTemplateColumn>
                    <telerik:GridEditCommandColumn>
                    </telerik:GridEditCommandColumn>
                </Columns>
            </MasterTableView>


Thanks,
Jayesh Goyani
0
Peter
Top achievements
Rank 1
answered on 05 Oct 2012, 07:55 AM
Thanks for the reply... That's what I was looking for.. I really appreciate it... 
Tags
Grid
Asked by
Peter
Top achievements
Rank 1
Answers by
Jayesh Goyani
Top achievements
Rank 2
Peter
Top achievements
Rank 1
Share this question
or