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

[Solved] visibility of GridNumericColumn of Telerik grid at runtime

9 Answers 359 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Syed
Top achievements
Rank 1
Syed asked on 09 Jan 2014, 01:24 AM

Hi There

I would like to make the visibility of GridNumericColumn of Telerik grid at runtime.

I have a control at my web page say dropdown box with three different values and what I want when dropdown box got a value single then I would like to make the visibility of GridNumericColumn to false.

I hope someone might be able to help me

Thanks

Syed

9 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 09 Jan 2014, 03:52 AM
Hi Syed,

You can hide the visibility of the GridNumericColumn from the DropDownList's OnSelectedIndexChanged event as follows:

C#:
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
    string value = DropDownList1.SelectedValue;
    if (value == "Single")
    {
        RadGrid1.MasterTableView.GetColumn("ColumnUniqueName").Visible = false;// Hide the GridNumericColumn
    }
    else
    {
        RadGrid1.MasterTableView.GetColumn("ColumnUniqueName").Visible = true;
        RadGrid1.Rebind();
    }
}

Thanks,
Princy
0
Syed
Top achievements
Rank 1
answered on 09 Jan 2014, 03:58 AM

Hi Princy

Thanks for your response, I much appreciate that. I would also like to hide the GridNumericColumn of Telerik grid at runtime while in insert as well as in editmode.

So on the web page if the value of DropDownList= “single” then I would like to hide the GridNumericColumn while inserting as well as editing

I am using VS 2012 with VB.net

I hope you understand that.

Many thanks

Syed

0
Accepted
Princy
Top achievements
Rank 2
answered on 09 Jan 2014, 04:13 AM
Hi Syed,

I guess you have the DropDownList inside the EditForm, here is a sample that i tried to Hide the GridNumericColumn in insert and edit mode based on the DropDownList selection:

ASPX:
<telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="false" OnNeedDataSource="RadGrid1_NeedDataSource"
    AutoGenerateEditColumn="true">
    <MasterTableView DataKeyNames="ID" CommandItemDisplay="Top">
        <Columns>
            <telerik:GridBoundColumn UniqueName="ID" DataField="ID" HeaderText="ID">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="Name" HeaderText="Name" UniqueName="Name" />
            <telerik:GridNumericColumn DataField="Number" HeaderText="Number" UniqueName="Number">
            </telerik:GridNumericColumn>
            <telerik:GridTemplateColumn EditFormHeaderTextFormat="Selection">
                <EditItemTemplate>
                    <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="true" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">
                        <asp:ListItem Text="Multiple" Value="Multiple">
                        </asp:ListItem>
                        <asp:ListItem Text="Single" Value="Single">
                        </asp:ListItem>
                    </asp:DropDownList>
                </EditItemTemplate>
            </telerik:GridTemplateColumn>
        </Columns>
    </MasterTableView>
</telerik:RadGrid>

VB:
Protected Sub RadGrid1_NeedDataSource(sender As Object, e As GridNeedDataSourceEventArgs)
    Dim data As dynamic = New () {New With { _
        Key .ID = 1, _
        Key .Name = "Name1", _
        Key .Number = "123" _
    }, New With { _
        Key .ID = 2, _
        Key .Name = "Name2", _
        Key .Number = "456" _
    }, New With { _
        Key .ID = 3, _
        Key .Name = "Name3", _
        Key .Number = "789" _
    }, New With { _
        Key .ID = 4, _
        Key .Name = "Name4", _
        Key .Number = "147" _
    }, New With { _
        Key .ID = 5, _
        Key .Name = "Name5", _
        Key .Number = "258" _
    }}
    RadGrid1.DataSource = data
End Sub
 
Protected Sub DropDownList1_SelectedIndexChanged(sender As Object, e As EventArgs)
    Dim drop As DropDownList = DirectCast(sender, DropDownList)
    Dim edit As GridEditableItem = DirectCast(drop.NamingContainer, GridEditableItem)
    Dim value As String = drop.SelectedValue
    Dim txt As RadNumericTextBox = DirectCast(edit("Number").Controls(0), RadNumericTextBox)
    If value = "Single" Then
        txt.Parent.Parent.Visible = False
        txt.Visible = False
    Else
        txt.Parent.Parent.Visible = True
        txt.Visible = True
    End If
End Sub

Thanks,
Princy

0
Syed
Top achievements
Rank 1
answered on 09 Jan 2014, 09:49 AM

Hi Princy

Great!  All worked

Many thanks

Syed

0
Syed
Top achievements
Rank 1
answered on 27 Jun 2014, 02:56 AM
Hi Princy
I have a Radgrid with many records and while updating It create copy of current month records  and put as  new records. I would like to make sure that person could not hit the button twice in one go. otherwise it will create two copies of the current month records. Is it possible I can disable update button after user click it. I am using EditCommandColumn.
Please update me it is urgent.
Thanks in advance
Syed
0
Syed
Top achievements
Rank 1
answered on 27 Jun 2014, 03:30 AM
It would be good If I disable the update  button using JavaScript thanks
0
Princy
Top achievements
Rank 2
answered on 27 Jun 2014, 09:18 AM
Hi Syed,

I guess you want to disable the Update button after a click. Since on Update the ItemCommand event fires, you can disable the button there as follows:

C#:
protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
{
  if (e.CommandName == RadGrid.UpdateCommandName)
  {
    GridEditableItem edit = (GridEditableItem)e.Item;
    //Access the Update Button and disable it
    LinkButton lnk = (LinkButton)edit.FindControl("UpdateButton");
    lnk.Enabled = false;     
  }
}

Thanks,
Princy
0
Syed
Top achievements
Rank 1
answered on 29 Jun 2014, 09:37 PM
Hi Princy
Thanks for your reply and I much appreciate that. Actually it does not disable the update button. Actually what is happening, I have a long process(at least 2 minutes long) which  run when a person hits update button in grid. What I want as soon as he hits the button he could not hit again so that my process could not rum more then one time. By using your code I can still hit my update button while the process is running. Please provide me some alternative either using JavaScript so that user could not hit the button again
Thanks
Syed 
0
Viktor Tachev
Telerik team
answered on 02 Jul 2014, 01:15 PM
Hello Syed,

I have answered your query in the other thread you have posted here. Please try the suggested approach there and let me know how it works.

This said, it is recommended to avoid posting duplicate threads. This would allow us to have better track of your support history and we would be able to provide better answers in shorter time. I suggest continuing the conversation in a single thread.

Regards,
Viktor Tachev
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
Grid
Asked by
Syed
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Syed
Top achievements
Rank 1
Viktor Tachev
Telerik team
Share this question
or