我在 RadGrid 中显示数据时遇到问题。数据源中有数据,但 RadGrid 不显示它。
asp代码:
<telerik:RadGrid ID="RadGrid1" runat="server" Width="980px"
EnableEmbeddedSkins="false"
AllowAutomaticDeletes="false"
AllowAutomaticInserts="false"
AllowAutomaticUpdates="true"
AllowPaging="true"
AutoGenerateColumns="False"
AutoGenerateDeleteColumn="false"
AutoGenerateEditColumn="false"
ItemStyle-Height="20px"
ClientSettings-ActiveRowIndex="true"
EnableViewState = "false"
OnNeedDataSource = "RadGrid1_NeedDataSource">
<MasterTableView AllowSorting="true" PageSize="10" Width="980px" EnableViewState="true"
RetrieveAllDataFields="false">
<NoRecordsTemplate>There is no data available.</NoRecordsTemplate>
<ExpandCollapseColumn FilterControlAltText="Filter ExpandColumn column"></ExpandCollapseColumn>
<Columns>
<telerik:GridBoundColumn DataField="TripId" HeaderText="Trip ID" SortExpression="TripID" UniqueName="TripId"
SortAscImageUrl="SortAsc.gif" SortDescImageUrl="SortDesc.gif">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="TripLegId" HeaderText="TripLegId" SortExpression="TripLegId" UniqueName="TripLegId"
SortAscImageUrl="SortAsc.gif" SortDescImageUrl="SortDesc.gif">
</telerik:GridBoundColumn>
<telerik:GridBoundColumn DataField="MemberFirstName" HeaderText="Member First Name" SortExpression="MemberFirstName"
UniqueName="MemberFirstName"
SortAscImageUrl="SortAsc.gif" SortDescImageUrl="SortDesc.gif">
</telerik:GridBoundColumn>
</Columns>
<PagerStyle FirstPageImageUrl="PagingFirst.gif"
LastPageImageUrl="PagingLast.gif" NextPageImageUrl="PagingNext.gif"
PrevPageImageUrl="PagingPrev.gif" />
<CommandItemStyle Font-Bold="True" ForeColor="#0066CC" />
</MasterTableView>
<ClientSettings>
<Selecting AllowRowSelect="true" />
</ClientSettings>
<FilterMenu EnableImageSprites="False"></FilterMenu>
</telerik:RadGrid>
.cs 代码
public void btnSearch_Clicked(object sender, EventArgs e)
{
try
{
RadGrid1.DataSource = GetTripsDataSet();
RadGrid1.DataBind();
this.RadGrid1.CurrentPageIndex = 0;
ViewState["newset"] = "new";
}
catch (Exception ex)
{
string errMessage = ex.Source.ToString();
}
}
protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
{
if (ViewState["newset"] == null) return;
if (Session["gridTrips"] != null)
{
DataTable dt = (DataTable)Session["griTrips"];
if (dt.Rows.Count > 0)
{
this.RadGrid1.DataSource = dt;
}
}
}