0
我在RadGrid中顯示數據時出現問題。數據源中有數據,但RadGrid不顯示它。Telerik RadGrid不顯示記錄
ASPX代碼:
<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;
}
}
}
您是否需要設置Session [「gridTrips」]?嘗試調用RadGrid1.Rebind() – PJM
也刪除RadGrid1.DataSource = GetTripsDataSet(); RadGrid1.DataBind(); – PJM