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

Radgrid hiding and showing columns

2 Answers 25 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Prasanna
Top achievements
Rank 1
Prasanna asked on 19 Sep 2011, 03:16 PM
hi all,


I have created a radgrid .It has some columns.Also I have radcombobox with checkboxes ,it has names of the radgrid column names Depending on the selection in the radcombobox  i want to show the columns in the radgrid.Note that  I have created radcombobox outside the radgrid.Please help me out to solve this problem.
Thanks in advance..

2 Answers, 1 is accepted

Sort by
0
Jayesh Goyani
Top achievements
Rank 2
answered on 20 Sep 2011, 07:12 AM
Hello,

    <telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="false" OnNeedDataSource="RadGrid1_NeedDataSource"
>
        <MasterTableView >
            <Columns>
                <telerik:GridBoundColumn DataField="ID" HeaderText="ID" UniqueName="ID">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="Name" HeaderText="Name" UniqueName="Name">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="ID" HeaderText="ID1" UniqueName="ID1">
                </telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="Name" HeaderText="Name1" UniqueName="Name1">
                </telerik:GridBoundColumn>
                <telerik:GridEditCommandColumn>
                </telerik:GridEditCommandColumn>
            </Columns>
        </MasterTableView>
        <ClientSettings EnableRowHoverStyle="true" AllowDragToGroup="true">
        </ClientSettings>
    </telerik:RadGrid>
    <br />
    <telerik:RadComboBox CheckBoxes="true" ID="RadComboBoxwithChk" runat="server">
        <Items>
            <telerik:RadComboBoxItem Text="ID" Value="ID" />
            <telerik:RadComboBoxItem Text="Name" Value="Name" />
            <telerik:RadComboBoxItem Text="ID1" Value="ID1" />
            <telerik:RadComboBoxItem Text="Name1" Value="Name1" />
        </Items>
    </telerik:RadComboBox>
    <asp:Button ID="Button1" runat="server" Text="Get Checked Items"
        OnClick="Button1_Click" />
protected void Button1_Click(object sender, EventArgs e)
    {
        foreach (RadComboBoxItem item in RadComboBoxwithChk.Items)
        {
            if(item.Checked)
            RadGrid1.MasterTableView.GetColumn(item.Text).Visible = true;
            else
                RadGrid1.MasterTableView.GetColumn(item.Text).Visible = false;
        }
 
        RadGrid1.Rebind();
    }
 
protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
    {
        DateTime dt = new DateTime();
 
        dynamic data = new[] {
                new { ID = 1, Name ="Name1", customdate=dt},
                new { ID = 2, Name = "Name2", customdate=dt},
                new { ID = 3, Name = "Name3", customdate=dt},
                new { ID = 4, Name = "Name4", customdate=dt.AddYears(2011)},
                new { ID = 5, Name = "Name5", customdate=dt}
            };
 
        RadGrid1.DataSource = data;
    }

let me know if any concern.

Thanks,
Jayesh Goyani
0
Prasanna
Top achievements
Rank 1
answered on 20 Sep 2011, 11:38 AM
Thanks for your reply. It works
Tags
General Discussions
Asked by
Prasanna
Top achievements
Rank 1
Answers by
Jayesh Goyani
Top achievements
Rank 2
Prasanna
Top achievements
Rank 1
Share this question
or