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

Hide a Grid Column based on DropDown Selection

5 Answers 1140 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Akki
Top achievements
Rank 1
Akki asked on 18 Feb 2013, 04:43 PM

Hi ,

I would like to hide the column of the radgrid based on value selected from dropdown. Following is the code.
On selectedIndexChanged i am finding the column and hiding.
For the first time works fine. When i select other, column is getting hidden but when i selected any other option,
 hidden column is not coming up even though i have made visible is true.

Do i need to do any other things.
Can u help me on this . ???

Regards,
Akki


<telerik:GridTemplateColumn UniqueName="group">
                            <HeaderTemplate>
                                <span class="errCopy">*</span>
                                <asp:Label ID="lblGrp" runat="server" Text="Group"></asp:Label>
                            </HeaderTemplate>
                            <ItemTemplate>
                                <asp:DropDownList ID="ddlGrp" runat="server" Width="100%" CssClass="textCopy"
                                AutoPostBack="true" OnSelectedIndexChanged="ddlGrp_SelectedIndexChanged">
                                </asp:DropDownList>
                            </ItemTemplate>
                        </telerik:GridTemplateColumn>
                        <telerik:GridTemplateColumn UniqueName="description">
                            <HeaderTemplate>
                                <asp:Label ID="lblDesc" runat="server" Text="Description,if Group"></asp:Label>
                            </HeaderTemplate>
                            <ItemTemplate>
                                <asp:TextBox ID="txtBxDesc" runat="server" Width="100%" CssClass="textCopy"
                                    MaxLength="100">
                                </asp:TextBox>
                            </ItemTemplate>
                        </telerik:GridTemplateColumn>



protected void ddlGrp_SelectedIndexChanged(object sender, EventArgs e)
        {
            DropDownList ddlSender = (DropDownList)sender;
            GridDataItem editForm = (GridDataItem)ddlSender.NamingContainer;
            DropDownList ddlAudGrp = (DropDownList)editForm.FindControl("ddlGrp");
            string abc = ddlAudGrp.SelectedItem.Text;
            if (abc == "Other")
            {
                rdGrp.MasterTableView.GetColumnSafe("group").Visible = true;
            }
            else
            {
                rdGrdAudienceGrp.MasterTableView.GetColumnSafe("group").Visible = false;
            }

             
        }

5 Answers, 1 is accepted

Sort by
0
Akki
Top achievements
Rank 1
answered on 19 Feb 2013, 03:02 AM
any help on this ??
0
Shinu
Top achievements
Rank 2
answered on 19 Feb 2013, 04:17 AM
Hi Akki,

I am not sure about your requirement. If you are making the GridTemplateColumn invisible which contains the DropDownList, you will not be able to select another item from the DropDownList . You don't need to access the DropDownList inside the SelectedIndexChanged event, if the sender is the same DropDownList. Please specify why are you using 'rdGrp' in the if condition and 'rdGrdAudienceGrp' in the else condition.

Thanks,
Shinu.
0
Akki
Top achievements
Rank 1
answered on 19 Feb 2013, 10:21 AM
Hi Shinu,

Sorry for the confusion.
rdGrdAudienceGrp is telerik gridname. once is select item from ddlGrp Dropdown which is inside grid,
I need to hide column ("group") which is inside grid. below is corrected code.


protected void ddlGrp_SelectedIndexChanged(object sender, EventArgs e)
        {
            DropDownList ddlSender = (DropDownList)sender;
            GridDataItem editForm = (GridDataItem)ddlSender.NamingContainer;
            DropDownList ddlAudGrp = (DropDownList)editForm.FindControl("ddlGrp");
            string abc = ddlAudGrp.SelectedItem.Text;
            if (abc == "Other")
            {
                rdGrdAudienceGrp.MasterTableView.GetColumnSafe("group").Visible = true;
            }
            else
            {
                rdGrdAudienceGrp.MasterTableView.GetColumnSafe("group").Visible = false;
            }

             
        }
0
Accepted
Shinu
Top achievements
Rank 2
answered on 20 Feb 2013, 05:00 AM
Hi Akki,

From your code I can see that the Column 'group' which you want to hide on the DropDownList's selected value is the same GridTemplateColumn which holds the DropDownList. If you are hiding the entire TemplateColumn in the SelectedIndexChanged event of the DropDownList, you will not be able to find the DropDownlist again to show the column. So I guess you want to hide any other column depending upon the value of the DropDownList. please take a look into the following code snippet to hide/show the 'description' field depending upon the value of the DropDownList.

C#:
protected void ddlGrp_SelectedIndexChanged(object sender, EventArgs e)
{
    DropDownList ddlSender = (DropDownList)sender;
    string abc = ddlSender.SelectedItem.Text;
    if (abc == "Other")
    {
         rdGrdAudienceGrp.MasterTableView.GetColumnSafe("description").Display = true;
    }
    else
    {
         rdGrdAudienceGrp.MasterTableView.GetColumnSafe("description").Display = false;
    }
}

Thanks,
Shinu.
0
Akki
Top achievements
Rank 1
answered on 20 Feb 2013, 07:44 AM
Thanks Shinu, thank you very much, You got it right.

Regards,
Akki
Tags
Grid
Asked by
Akki
Top achievements
Rank 1
Answers by
Akki
Top achievements
Rank 1
Shinu
Top achievements
Rank 2
Share this question
or