将数据绑定到asp.net中的telerik数据网格

时间:2013-04-02 04:19:03

标签: c# asp.net datagrid telerik

我有下面的代码,我将数据从数据库绑定到telerik数据网格“gridCommon”。

gridCommon.DataSource = DbContext.MTO_General_Commons.ToList();

在我的aspx中,

  <telerik:RadGrid ID="gridCommon" runat="server" AllowPaging="True" AllowSorting="True"
        AutoGenerateColumns="False" ShowStatusBar="True" CellSpacing="0" GridLines="None"
        Width="470px" OnNeedDataSource="gridCommon_dataRebind" OnInsertCommand="gridCommonInsert"
        OnUpdateCommand="gridCommonUpdate" OnDeleteCommand="gridCommonDelete">
        <MasterTableView DataKeyNames="CommonID" CommandItemDisplay="Top">
            <CommandItemSettings ExportToPdfText="Export to PDF"></CommandItemSettings>
            <RowIndicatorColumn Visible="True" FilterControlAltText="Filter RowIndicator column">
            </RowIndicatorColumn>
            <ExpandCollapseColumn Visible="True" FilterControlAltText="Filter ExpandColumn column">
            </ExpandCollapseColumn>
            <Columns>
                <telerik:GridButtonColumn ButtonType="ImageButton" CommandName="Edit" UniqueName="EditCommandColmun">
                </telerik:GridButtonColumn>
                <telerik:GridBoundColumn DataField="Name" FilterControlAltText="Filter Name column"
                    HeaderText="Name" UniqueName="Name">
                </telerik:GridBoundColumn>
                <telerik:GridButtonColumn ConfirmText="Are you sure to delete ?" ConfirmDialogType="RadWindow"
                    ConfirmTitle="Delete" ButtonType="ImageButton" CommandName="Delete">
                </telerik:GridButtonColumn>
            </Columns>
        </MasterTableView>
        <FilterMenu EnableImageSprites="False">
        </FilterMenu>
    </telerik:RadGrid>

但是gridArea没有显示数据,我想知道为什么?

1 个答案:

答案 0 :(得分:3)

gridCommon.DataSource = DbContext.MTO_General_Commons.ToList();
gridCommon.DataBind();