I am trying to hide a column based on a value in the querystring and it continues to show: I have tried it 2 different ways and cannot figure out what I am doing wrong....
We are passing the country and if it is Canada we want to show the other column and if it is US we want to show the state drop downlist.
asp.net:
<telerik:RadGrid ID="RadGrid1" runat="server" DataSourceID="dsLocation" GridLines="None"
AllowAutomaticUpdates="True" AllowAutomaticInserts="True" ShowStatusBar="True"
AllowSorting="True" OnDataBound="RadGrid1_DataBound" Skin="Default"
OnItemCommand="RadGrid1_ItemCommand">
<PagerStyle Mode="NextPrevAndNumeric" />
<MasterTableView DataKeyNames="testid" DataSourceID="dsLocation" AutoGenerateColumns="false"
CommandItemDisplay="Top" AllowMultiColumnSorting="True">
<CommandItemSettings AddNewRecordText="Add new record" />
<ExpandCollapseColumn Visible="True">
</ExpandCollapseColumn>
<Columns>
<telerik:GridEditCommandColumn ButtonType="ImageButton">
<HeaderStyle Width="20px" />
<ItemStyle CssClass="MyImageButton" />
</telerik:GridEditCommandColumn>
<telerik:GridTemplateColumn HeaderText="State" SortExpression="StateID" UniqueName="TemplateColumn2" Display="True"
EditFormColumnIndex="0">
<EditItemTemplate>
<br />
<asp:dropdownlist DataField="StateID" id="ddlStateID" runat="server" DataSourceID="dsStates" DataTextField="StateCode" DataValueField="StateID" AppendDataBoundItems="true"
SelectedValue='<%# Bind("StateID") %>' AutoPostBack="True" >
<asp:ListItem Selected="True" Text="Please select a state" Value=""/>
</asp:dropdownlist>
</EditItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridBoundColumn DataField="Other" HeaderText="Other"
SortExpression="Other" UniqueName="Other" Display="true">
</telerik:GridBoundColumn>
</Columns>
<EditFormSettings>
<EditColumn ButtonType="ImageButton" />
</EditFormSettings>
</MasterTableView>
</telerik:RadGrid>
code:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
if (Request.QueryString["Canada"] == "Y")
{
RadGrid1.MasterTableView.GetColumn("Other").Visible = true;
RadGrid1.MasterTableView.GetColumn("TemplateColumn2").Visible = false;
RadGrid1.MasterTableView.Rebind();
}
else
{
RadGrid1.MasterTableView.GetColumn("Other").Visible = false;
RadGrid1.MasterTableView.GetColumn("TemplateColumn2").Visible = true;
RadGrid1.MasterTableView.Rebind();
}
}
}
protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e)
{
foreach (GridColumn col in RadGrid1.Columns)
{
if (col.ColumnType == "GridBoundColumn" && col.UniqueName == "Other")
{
if (e.CommandName == RadGrid.EditCommandName)
{
(col as GridTemplateColumn).ReadOnly = true;
col.Visible = false;
}
else
{
(col as GridTemplateColumn).ReadOnly = false;
col.Visible = true;
}
}
}
}
Any insight would be greatly appreciated....
Julie
We are passing the country and if it is Canada we want to show the other column and if it is US we want to show the state drop downlist.
asp.net:
<telerik:RadGrid ID="RadGrid1" runat="server" DataSourceID="dsLocation" GridLines="None"
AllowAutomaticUpdates="True" AllowAutomaticInserts="True" ShowStatusBar="True"
AllowSorting="True" OnDataBound="RadGrid1_DataBound" Skin="Default"
OnItemCommand="RadGrid1_ItemCommand">
<PagerStyle Mode="NextPrevAndNumeric" />
<MasterTableView DataKeyNames="testid" DataSourceID="dsLocation" AutoGenerateColumns="false"
CommandItemDisplay="Top" AllowMultiColumnSorting="True">
<CommandItemSettings AddNewRecordText="Add new record" />
<ExpandCollapseColumn Visible="True">
</ExpandCollapseColumn>
<Columns>
<telerik:GridEditCommandColumn ButtonType="ImageButton">
<HeaderStyle Width="20px" />
<ItemStyle CssClass="MyImageButton" />
</telerik:GridEditCommandColumn>
<telerik:GridTemplateColumn HeaderText="State" SortExpression="StateID" UniqueName="TemplateColumn2" Display="True"
EditFormColumnIndex="0">
<EditItemTemplate>
<br />
<asp:dropdownlist DataField="StateID" id="ddlStateID" runat="server" DataSourceID="dsStates" DataTextField="StateCode" DataValueField="StateID" AppendDataBoundItems="true"
SelectedValue='<%# Bind("StateID") %>' AutoPostBack="True" >
<asp:ListItem Selected="True" Text="Please select a state" Value=""/>
</asp:dropdownlist>
</EditItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridBoundColumn DataField="Other" HeaderText="Other"
SortExpression="Other" UniqueName="Other" Display="true">
</telerik:GridBoundColumn>
</Columns>
<EditFormSettings>
<EditColumn ButtonType="ImageButton" />
</EditFormSettings>
</MasterTableView>
</telerik:RadGrid>
code:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
if (Request.QueryString["Canada"] == "Y")
{
RadGrid1.MasterTableView.GetColumn("Other").Visible = true;
RadGrid1.MasterTableView.GetColumn("TemplateColumn2").Visible = false;
RadGrid1.MasterTableView.Rebind();
}
else
{
RadGrid1.MasterTableView.GetColumn("Other").Visible = false;
RadGrid1.MasterTableView.GetColumn("TemplateColumn2").Visible = true;
RadGrid1.MasterTableView.Rebind();
}
}
}
protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e)
{
foreach (GridColumn col in RadGrid1.Columns)
{
if (col.ColumnType == "GridBoundColumn" && col.UniqueName == "Other")
{
if (e.CommandName == RadGrid.EditCommandName)
{
(col as GridTemplateColumn).ReadOnly = true;
col.Visible = false;
}
else
{
(col as GridTemplateColumn).ReadOnly = false;
col.Visible = true;
}
}
}
}
Any insight would be greatly appreciated....
Julie