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

RadGrid AutoGenerateColumns false

3 Answers 380 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Saul
Top achievements
Rank 1
Saul asked on 06 Jul 2015, 03:56 PM

Hi! I'm trying to make a radgrid with explicit defined columns. I've tried setting the AutoGenerateColumns property of the radgrid to false, but it won't show anything. This is my code

<telerik:RadGrid ID="rdContainers"  runat="server" AutoGenerateColumns="false" OnNeedDataSource="fnGetScanContainers" AllowFilteringByColumn="True" Width="91%">
                    <telerik:MasterTableView  TableLayout="Fixed">
                        <HeaderStyle Width="102px" />
                        <Columns>
                            <telerik:GridBoundColumn DataField="ContainerID" HeaderText="Container ID" SortExpression="ContainerID" UniqueName="gcContainerID" FilterControlWidth="60px">
                                <HeaderStyle Width="170px" />
                            </telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="Location" HeaderText="Location" UniqueName="gcLocation" FilterControlWidth="60px">
                                 <HeaderStyle Width="115px" />
                            </telerik:GridBoundColumn>
                            <telerik:GridBoundColumn DataField="PartNumber" HeaderText="Part Number" UniqueName="gcPartNumber" FilterControlWidth="60px">
                                 <HeaderStyle Width="115px" />
                            </telerik:GridBoundColumn>
                    </telerik:MasterTableView>
                    <ClientSettings EnableRowHoverStyle="true">
                                <Selecting AllowRowSelect="true" EnableDragToSelectRows="false" />
                                <Scrolling AllowScroll="true" UseStaticHeaders="true" ScrollHeight="" />
                    </ClientSettings>
</telerik:RadGrid>

 

3 Answers, 1 is accepted

Sort by
0
Saul
Top achievements
Rank 1
answered on 06 Jul 2015, 05:49 PM

If I remove the AutoGenerateColumns="false" the RadGrid shows all the columns from my DataTable source. However, I'd like to define the columns by myself. This is how I set the DataSource

protected void fnGetScanContainers(object sender, EventArgs e) {
            objScanContainer = new ScanContainer();
            rdContainers.DataSource = objScanContainer.GetHDDReceivedDescription();  //This function retrieves the DataTable
}

0
Saul
Top achievements
Rank 1
answered on 07 Jul 2015, 02:43 PM

Nevermind, the problem was in my MasterTableView tag

0
Accepted
Viktor Tachev
Telerik team
answered on 08 Jul 2015, 02:02 PM
Hello Saul,

I have examined the provided code and the closing Columns tag seems to be missing. Try to add it and see how the behavior changes.


<telerik:RadGrid ID="rdContainers" runat="server" AutoGenerateColumns="false" OnNeedDataSource="fnGetScanContainers" AllowFilteringByColumn="True" Width="91%">
    <telerik:MasterTableView TableLayout="Fixed">
        <HeaderStyle Width="102px" />
        <Columns>
            <telerik:GridBoundColumn DataField="ContainerID" HeaderText="Container ID" SortExpression="ContainerID" UniqueName="gcContainerID" FilterControlWidth="60px">
                <HeaderStyle Width="170px" />
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="Location" HeaderText="Location" UniqueName="gcLocation" FilterControlWidth="60px">
                <HeaderStyle Width="115px" />
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="PartNumber" HeaderText="Part Number" UniqueName="gcPartNumber" FilterControlWidth="60px">
                <HeaderStyle Width="115px" />
            </telerik:GridBoundColumn>
        </Columns>
    </telerik:MasterTableView>
    <ClientSettings EnableRowHoverStyle="true">
        <Selecting AllowRowSelect="true" EnableDragToSelectRows="false" />
        <Scrolling AllowScroll="true" UseStaticHeaders="true" ScrollHeight="" />
    </ClientSettings>
</telerik:RadGrid>



Regards,
Viktor Tachev
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
Grid
Asked by
Saul
Top achievements
Rank 1
Answers by
Saul
Top achievements
Rank 1
Viktor Tachev
Telerik team
Share this question
or