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

Telerik UI ASP.net RADGRID set column of checkbox programmatically

8 Answers 149 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Daniel
Top achievements
Rank 1
Daniel asked on 02 Mar 2014, 09:58 AM
Hi

I am trying to display a column of checkboxes in Telerik RadGrid in my project.
The data source of my grid is a list of objects.
How to do this  programatically ?

p.s.
an answer in any programming language will be appreciated 

my code:

    
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    If Not IsPostBack Then
      setColumnsOnGrid(Of object)(lst, RadGrid1, ArrayNameFilds:={"column1", "column2", "column3 ", "etc."})
    End If
End Sub
 
Private Sub setColumnsOnGrid(Of T)(ByVal lst As List(Of T), ByVal grdName As RadGrid, ByVal ArrayNameFilds As Array)
    Dim nameFiled As String
    grdName.DataSource = lst
    grdName.AllowMultiRowSelection = True
    grdName.MasterTableView.AutoGenerateColumns = False
 
    Dim boundColumn As GridBoundColumn
 
    For i As Integer = 0 To ArrayNameFilds.Length - 1
        nameFiled = ArrayNameFilds(i).ToString()
        boundColumn = New GridBoundColumn()
        grdName.MasterTableView.Columns.Add(boundColumn)
        boundColumn.DataField = nameFiled
        boundColumn.HeaderText = nameFiled
     Next
End Sub


my aspx:

<telerik:RadGrid ID="grd_test" runat="server" AllowFilteringByColumn="True" AllowPaging="True" AllowSorting="True" CellSpacing="0" GridLines="None">
    <ClientSettings>
        <Scrolling AllowScroll="True" UseStaticHeaders="True" />
    </ClientSettings>
</telerik:RadGrid>

8 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 03 Mar 2014, 12:36 PM
Hi Daniel,

Please take a look at this article on Creating a RadGrid Programmatically  to create checkboxes dynamically. You can use template columns to create the checkboxes.

Thanks,
Princy
0
Daniel
Top achievements
Rank 1
answered on 12 Mar 2014, 02:23 PM
Princy.
Thank you very much for the help 
But unfortunately it does not work. 

I found the answer in your forums (Jayesh Goyani wrote): 

Dim objGridClientSelectColumn As GridClientSelectColumn = New GridClientSelectColumn()
objGridClientSelectColumn.UniqueName = "UniqueName"
grdName.MasterTableView.Columns.Add(objGridClientSelectColumn)


Daniel

0
Onkaramurthy
Top achievements
Rank 1
answered on 10 Apr 2014, 04:15 PM
Hi ,

I am facing one Issue in RadGrid Control,

I have two Radgrids Side by Side, Out of Two Grids First Grid is Static(All columns) & Second Grid is Dynamic(All Columns),

how to set the same row height for both the grids, I used Itemstyle-height attribute but its not helping, I have Attached Screen Shot also, 

if any one suggest some idea's means it helps lot for me,

























0
Princy
Top achievements
Rank 2
answered on 11 Apr 2014, 03:56 AM
Hi Onkaramurthy,

You can set the height of your rows in aspx as well as code behind as follows. If this doesn't help, provide your full code snippet.

ASPX:
<telerik:RadGrid ID="RadGrid1" runat="server">
    <MasterTableView >
        <ItemStyle Height="100px" />
        <AlternatingItemStyle Height="100px" />     
            . . . . .
    </MasterTableView>
</telerik:RadGrid>

C#:
RadGrid2.MasterTableView.ItemStyle.Height = Unit.Pixel(100);
RadGrid2.MasterTableView.AlternatingItemStyle.Height = Unit.Pixel(100);

Thanks,
Princy
0
Onkaramurthy
Top achievements
Rank 1
answered on 11 Apr 2014, 08:15 AM
Thanks for your Reply,

Provided solution not working,

I ll provide the code snippet, Please have a look on it, let me know further,

one more thing in some browser its coming properly But In some browsers it meshing up ( Browser IE), 

Static Grid
<telerik:RadGrid ID="RadGrid1" runat="server" Skin="Office2007" GridLines="None"
                                ShowHeader="true" Height="810px" AllowFilteringByColumn="false" AllowPaging="True"
                                PageSize="30" AllowSorting="True" AutoGenerateColumns="False" Width="100%" ShowStatusBar="true"
                                OnItemDataBound="RadGrid1_ItemDataBound" OnNeedDataSource="RadGrid1_NeedDataSource"
                                AllowAutomaticUpdates="False" HorizontalAlign="NotSet" ShowFooter="true">
                                <ClientSettings AllowColumnHide="True" AllowRowHide="True" AllowColumnsReorder="false"
                                    ReorderColumnsOnClient="false">
                                    <Scrolling AllowScroll="false" FrozenColumnsCount="10" ScrollHeight="240px" UseStaticHeaders="true">
                                    </Scrolling>
                                    <Resizing EnableRealTimeResize="false" ResizeGridOnColumnResize="false" AllowColumnResize="false"
                                        ClipCellContentOnResize="false"></Resizing>
                                </ClientSettings>
                                <MasterTableView CommandItemDisplay="None" EditMode="PopUp" ShowGroupFooter="true"
                                    TableLayout="Fixed">
                                    <Columns>
                                        <telerik:GridBoundColumn UniqueName="oid" HeaderText="oid" DataField="oid" Visible="false" ItemStyle-Height="23px"
                                            HeaderStyle-Width="200px" />
                                        <telerik:GridTemplateColumn HeaderText="Month" HeaderStyle-Width="70px" Visible="true"
                                            AllowFiltering="false" ShowFilterIcon="false" UniqueName="gtcStartMonth">
                                            <ItemStyle Height="23px"></ItemStyle>
                                            <ItemTemplate>
                                                <telerik:RadComboBox ID="rcbGridStartMonth" runat="server" AutoPostBack="false" Width="50px"
                                                    EmptyMessage="Select a month" AllowCustomText="true">
                                                    <Items>
                                                        <telerik:RadComboBoxItem Text="Jan" Value="1" />
                                                        <telerik:RadComboBoxItem Text="Feb" Value="2" />
                                                        <telerik:RadComboBoxItem Text="Mar" Value="3" />
                                                        <telerik:RadComboBoxItem Text="Apr" Value="4" />
                                                        <telerik:RadComboBoxItem Text="May" Value="5" />
                                                        <telerik:RadComboBoxItem Text="Jun" Value="6" />
                                                        <telerik:RadComboBoxItem Text="Jul" Value="7" />
                                                        <telerik:RadComboBoxItem Text="Aug" Value="8" />
                                                        <telerik:RadComboBoxItem Text="Sep" Value="9" />
                                                        <telerik:RadComboBoxItem Text="Oct" Value="10" />
                                                        <telerik:RadComboBoxItem Text="Nov" Value="11" />
                                                        <telerik:RadComboBoxItem Text="Dec" Value="12" />
                                                    </Items>
                                                </telerik:RadComboBox>
                                            </ItemTemplate>
                                        </telerik:GridTemplateColumn>
                                        <telerik:GridTemplateColumn HeaderText="Year" HeaderStyle-Width="70px" Visible="true"
                                            AllowFiltering="false" ShowFilterIcon="false" UniqueName="gtcStartYear">
                                            <ItemStyle Height="23px"></ItemStyle>
                                            <ItemTemplate>
                                                <telerik:RadComboBox ID="rcbGridStartYear" runat="server" AutoPostBack="false" Width="60px"
                                                    EmptyMessage="Select a year" AllowCustomText="true">
                                                    <Items>
                                                        <telerik:RadComboBoxItem Text="2008" Value="2008" />
                                                        <telerik:RadComboBoxItem Text="2009" Value="2009" />
                                                        <telerik:RadComboBoxItem Text="2010" Value="2010" />
                                                        <telerik:RadComboBoxItem Text="2011" Value="2011" />
                                                        <telerik:RadComboBoxItem Text="2012" Value="2012" />
                                                        <telerik:RadComboBoxItem Text="2013" Value="2013" />
                                                        <telerik:RadComboBoxItem Text="2014" Value="2014" />
                                                    </Items>
                                                </telerik:RadComboBox>
                                            </ItemTemplate>
                                        </telerik:GridTemplateColumn>
                                        <telerik:GridTemplateColumn HeaderText="Month" HeaderStyle-Width="70px" Visible="true"
                                            AllowFiltering="false" ShowFilterIcon="false" UniqueName="gtcEndMonth">
                                            <ItemStyle Height="23px"></ItemStyle>
                                            <ItemTemplate>
                                                <telerik:RadComboBox ID="rcbGridEndMonth" runat="server" AutoPostBack="false" Width="50px"
                                                    EmptyMessage="Select a month" AllowCustomText="true">
                                                    <Items>
                                                        <telerik:RadComboBoxItem Text="Jan" Value="1" />
                                                        <telerik:RadComboBoxItem Text="Feb" Value="2" />
                                                        <telerik:RadComboBoxItem Text="Mar" Value="3" />
                                                        <telerik:RadComboBoxItem Text="Apr" Value="4" />
                                                        <telerik:RadComboBoxItem Text="May" Value="5" />
                                                        <telerik:RadComboBoxItem Text="Jun" Value="6" />
                                                        <telerik:RadComboBoxItem Text="Jul" Value="7" />
                                                        <telerik:RadComboBoxItem Text="Aug" Value="8" />
                                                        <telerik:RadComboBoxItem Text="Sep" Value="9" />
                                                        <telerik:RadComboBoxItem Text="Oct" Value="10" />
                                                        <telerik:RadComboBoxItem Text="Nov" Value="11" />
                                                        <telerik:RadComboBoxItem Text="Dec" Value="12" />
                                                    </Items>
                                                </telerik:RadComboBox>
                                            </ItemTemplate>
                                        </telerik:GridTemplateColumn>
                                        <telerik:GridTemplateColumn HeaderText="Year" HeaderStyle-Width="70px" Visible="true"
                                            AllowFiltering="false" ShowFilterIcon="false" UniqueName="gtcEndYear">
                                            <ItemStyle Height="23px"></ItemStyle>
                                            <ItemTemplate>
                                                <telerik:RadComboBox ID="rcbGridEndYear" runat="server" AutoPostBack="false" Width="60px"
                                                    EmptyMessage="Select a year" AllowCustomText="true">
                                                    <Items>
                                                        <telerik:RadComboBoxItem Text="2008" Value="2008" />
                                                        <telerik:RadComboBoxItem Text="2009" Value="2009" />
                                                        <telerik:RadComboBoxItem Text="2010" Value="2010" />
                                                        <telerik:RadComboBoxItem Text="2011" Value="2011" />
                                                        <telerik:RadComboBoxItem Text="2012" Value="2012" />
                                                        <telerik:RadComboBoxItem Text="2013" Value="2013" />
                                                        <telerik:RadComboBoxItem Text="2014" Value="2014" />
                                                    </Items>
                                                </telerik:RadComboBox>
                                            </ItemTemplate>
                                        </telerik:GridTemplateColumn>
                                        <%--<telerik:GridBoundColumn UniqueName="GroupName"  HeaderText="Expense Category" DataField="GroupName" Visible="true" HeaderStyle-Width="200px" />--%>
                                        <telerik:GridTemplateColumn HeaderText="Expense Category" HeaderStyle-Width="200px"
                                            Visible="true" AllowFiltering="false" ShowFilterIcon="false" UniqueName="GroupName">
                                            <ItemStyle Height="23px"></ItemStyle>
                                            <ItemTemplate>
                                                <telerik:RadButton ID="rbnGroupName" runat="server" ButtonType="StandardButton" Text='<%# Bind( "GroupName") %>'
                                                    Width="100%" OnClick="rbnCategory_OnClick" Visible="true" AutoPostBack="true">
                                                </telerik:RadButton>
                                            </ItemTemplate>
                                        </telerik:GridTemplateColumn>
                                        <%-- <telerik:GridBoundColumn UniqueName="TotalWells"  HeaderText="Total #Wells" DataField="TotalWells" Visible="true" HeaderStyle-Width="90px" />--%>
                                        <telerik:GridTemplateColumn HeaderText="Total #Wells" HeaderStyle-Width="90px" Visible="true"
                                            AllowFiltering="false" ShowFilterIcon="false" UniqueName="TotalWells">
                                            <ItemStyle Height="23px"></ItemStyle>
                                            <ItemTemplate>
                                                <telerik:RadNumericTextBox ID="rntbTotalWells" runat="Server" Width="100%" Text='<%# Bind( "TotalWells") %>'>
                                                    <NumberFormat GroupSeparator="," DecimalDigits="0" AllowRounding="true" KeepNotRoundedValue="false" />
                                                </telerik:RadNumericTextBox>
                                            </ItemTemplate>
                                        </telerik:GridTemplateColumn>
</RadGrid>

Dynamic Grid

<telerik:RadGrid ID="RadGrid2" runat="server" Skin="Office2007" GridLines="None"
                            ShowHeader="true" Height="810px" AllowFilteringByColumn="false" AllowPaging="True"
                            PageSize="30" AllowSorting="True" AutoGenerateColumns="False" Width="100%" ShowStatusBar="true"
                            OnNeedDataSource="RadGrid2_NeedDataSource" AllowAutomaticUpdates="False" HorizontalAlign="NotSet"
                            ShowFooter="true">
                            <ClientSettings AllowColumnHide="True" AllowRowHide="false" AllowColumnsReorder="false"
                                ReorderColumnsOnClient="false">
                                <Scrolling AllowScroll="false" ScrollHeight="240px" UseStaticHeaders="true"></Scrolling>
                            </ClientSettings>
                            <MasterTableView CommandItemDisplay="None" ShowGroupFooter="true" TableLayout="Fixed">
                                <Columns>
                                </Columns>
                            </MasterTableView>
 </telerik:RadGrid>

Dynamic Grid C# Code

this.RadGrid2.MasterTableView.Columns.Clear();
GridBoundColumn boundColumn;

boundColumn = new GridBoundColumn();
                        this.RadGrid2.MasterTableView.Columns.Add(boundColumn);
                        boundColumn.DataField = dsComm.Tables[0].Columns[i].ColumnName;
                        boundColumn.HeaderText = dsComm.Tables[0].Columns[i].ColumnName;
                        boundColumn.UniqueName = dsComm.Tables[0].Columns[i].ColumnName;
                        boundColumn.AllowFiltering = false;
                        boundColumn.AllowSorting = true;
                        boundColumn.HeaderStyle.Width = Unit.Pixel(80);
                        boundColumn.DataFormatString = "{0:C0}";
                        boundColumn.ItemStyle.Height = Unit.Pixel(23);
                        boundColumn.Aggregate = GridAggregateFunction.Sum;
0
Princy
Top achievements
Rank 2
answered on 14 Apr 2014, 06:27 AM
Hi Onkaramurthy,

Please try the solution mentioned in this forum and check if it helps you to set the height.
http://www.telerik.com/forums/itemstyle-height-different-in-firefox-ie7#xLbFHln4fk2tsjmABbGD7A

Thanks,
Princy
0
Onkaramurthy
Top achievements
Rank 1
answered on 14 Apr 2014, 07:42 AM
Hi Princy,

I tried with Mentioned Solution in that Link, But it is not working,

Thanks
Onkar,
0
Viktor Tachev
Telerik team
answered on 15 Apr 2014, 03:12 PM
Hello,

Try using CSS to define the look of the RadGrid controls. Remove all properties in the markup that use inline styles and place the following CSS rule on the page.

.rgRow,
.rgAltRow {
    height: 40px;
}


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
Daniel
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Daniel
Top achievements
Rank 1
Onkaramurthy
Top achievements
Rank 1
Viktor Tachev
Telerik team
Share this question
or