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

Hiding template Column dynamically

2 Answers 326 Views
Grid
This is a migrated thread and some comments may be shown as answers.
vijay
Top achievements
Rank 1
vijay asked on 03 Feb 2011, 05:44 AM

 

Hi..
    Here i have two code snipets.  In first i used bound column for displaying record in rad grid in runtime.  
If i using template column its not working (It throughing an error like Data binding error).

My concept is IF i get the column from database means it should show the Data value Else column should be disappear.

PLEASE HELP ME ON THIS ISSUE... Thanks in advance.
  
WORKING
------------------------------------------------------

public void Bind_grid()

        {

            tkgvPerformance.Columns[0].Visible = false;

           

            string Query = "select c.DepartmentID from tblEMP c";

            tkgvPerformance.DataSource = Fs.GetDataTable(Query, CommandType.Text);

            tkgvPerformance.DataBind();

        }

 

 

 

<telerik:RadGrid ID="tkgvPerformance" runat="server" AutoGenerateColumns="False"

                        GridLines="None" Skin="Sunset" AllowFilteringByColumn="True" AllowSorting="True">

                        <HeaderContextMenu EnableImageSprites="True" CssClass="GridContextMenu GridContextMenu_Default">

                        </HeaderContextMenu>

                        <MasterTableView>

                            <CommandItemSettings ExportToPdfText="Export to Pdf"></CommandItemSettings>

                            <Columns>

                                <telerik:GridBoundColumn DataField="EMPname" HeaderText="CourseName" UniqueName="CourseName">

                                </telerik:GridBoundColumn>

                                <telerik:GridTemplateColumn UniqueName="TemplateColumn" HeaderText="Sub1">

                                    <ItemTemplate>

                                        <asp:CheckBox ID="CheckBox1" runat="server" Text='<%#Eval("DepartmentID") %>' ForeColor="Red"

                                            Font-Bold="true" />

                                        <telerik:RadNumericTextBox ID="txtPassMark" runat="server" MaxLength="3" Width="35px">

                                        </telerik:RadNumericTextBox>

                                        <telerik:RadNumericTextBox ID="RadNumericTextBox1" runat="server" MaxLength="3" Width="35px">

                                        </telerik:RadNumericTextBox>

                                        <asp:Label ID="Label1" runat="server" Text="100" ForeColor="Gray"></asp:Label>

                                    </ItemTemplate>

                                    <ItemStyle CssClass="style1" />

                                </telerik:GridTemplateColumn>

                            </Columns>

                        </MasterTableView>

                    </telerik:RadGrid>



NOTWORKING
------------------------------------------------------
public void Bind_grid()

        {

            tkgvPerformance.Columns[1].Visible = false;

           

            string Query = "select c.EMPname from tblEMP c";

            tkgvPerformance.DataSource = Fs.GetDataTable(Query, CommandType.Text);

            tkgvPerformance.DataBind();

        }

 

 

 

<telerik:RadGrid ID="tkgvPerformance" runat="server" AutoGenerateColumns="False"

                        GridLines="None" Skin="Sunset" AllowFilteringByColumn="True" AllowSorting="True">

                        <HeaderContextMenu EnableImageSprites="True" CssClass="GridContextMenu GridContextMenu_Default">

                        </HeaderContextMenu>

                        <MasterTableView>

                            <CommandItemSettings ExportToPdfText="Export to Pdf"></CommandItemSettings>

                            <Columns>

                                <telerik:GridBoundColumn DataField="EMPname" HeaderText="CourseName" UniqueName="CourseName">

                                </telerik:GridBoundColumn>

                                <telerik:GridTemplateColumn UniqueName="TemplateColumn" HeaderText="Sub1">

                                    <ItemTemplate>

                                        <asp:CheckBox ID="CheckBox1" runat="server" Text='<%#Eval("DepartmentID") %>' ForeColor="Red"

                                            Font-Bold="true" />

                                        <telerik:RadNumericTextBox ID="txtPassMark" runat="server" MaxLength="3" Width="35px">

                                        </telerik:RadNumericTextBox>

                                        <telerik:RadNumericTextBox ID="RadNumericTextBox1" runat="server" MaxLength="3" Width="35px">

                                        </telerik:RadNumericTextBox>

                                        <asp:Label ID="Label1" runat="server" Text="100" ForeColor="Gray"></asp:Label>

                                    </ItemTemplate>

                                    <ItemStyle CssClass="style1" />

                                </telerik:GridTemplateColumn>

                            </Columns>

                        </MasterTableView>

                    </telerik:RadGrid>

2 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 03 Feb 2011, 08:46 AM
Hello Vijay,

I am not quite sure about your requirement. If you want to hide the TemplateColumn from code behind, try the following approach and check whether it works.
C#:
tkgvPerformance.MasterTableView.GetColumn("TemplateColumn").Visible = false;

If you want to show/hide TemplateColumn based on some condition you can try it in Prerender event. Please elaborate your requirement and the error you are getting when hiding the column.

Thanks,
Princy.
0
Hatem
Top achievements
Rank 1
answered on 19 Sep 2016, 12:53 PM
i tried that code but it doesn't  work
Tags
Grid
Asked by
vijay
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Hatem
Top achievements
Rank 1
Share this question
or