Hiding template Column dynamically

3 posts, 0 answers
  1. vijay
    vijay avatar
    17 posts
    Member since:
    Dec 2010

    Posted 02 Feb 2011 Link to this post

     

    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. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 03 Feb 2011 Link to this post

    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Hatem
    Hatem avatar
    1 posts
    Member since:
    Sep 2016

    Posted 19 Sep Link to this post

    i tried that code but it doesn't  work
Back to Top