我在我的 radgrid 中有自动生成的列,我试图在输入键时启用列过滤。当我输入搜索文本并按 Enter 时,我收到以下错误。
未捕获的类型错误:无法读取 null 的属性“值”
<telerik:RadGrid ID="gridSearchL3" runat="server" AllowPagg="True"
GridLines="None" Height="415px"
OnNeedDataSource="RadGrid1_NeedDataSource"
Font-Names="Eras Medium ITC" Font-Size="Small" PageSize="50"
AllowFilteringByColumn="True"
AllowSorting="True" ShowStatusBar="True" AllowPaging="True" CellSpacing="0"
oncolumncreated="gridSearchL3_ColumnCreated1" onitemcommand="gridSearchL3_ItemCommand"
>
<FilterItemStyle Font-Names="Eras Medium ITC" Font-Size="XX-Small" />
<GroupingSettings CaseSensitive="False" />
<ExportSettings Excel-Format="ExcelML" ExportOnlyData="True"
FileName="PinC Group" IgnorePaging="True" OpenInNewWindow="True">
<Excel Format="ExcelML" />
</ExportSettings>
<ClientSettings>
<Selecting AllowRowSelect="True" />
<Scrolling AllowScroll="True" UseStaticHeaders="True" />
</ClientSettings>
<AlternatingItemStyle Font-Names="Eras Medium ITC" Font-Size="X-Small" />
<GroupHeaderItemStyle Font-Names="Eras Medium ITC" Font-Size="X-Small" />
<SortingSettings EnableSkinSortStyles="false" />
<MasterTableView Font-Names="Eras Medium ITC"
Font-Size="X-Small">
<CommandItemSettings ExportToPdfText="Export to Pdf" />
<RowIndicatorColumn FilterControlAltText="Filter RowIndicator column">
</RowIndicatorColumn>
<ExpandCollapseColumn FilterControlAltText="Filter ExpandColumn column">
</ExpandCollapseColumn>
<EditFormSettings>
<EditColumn FilterControlAltText="Filter EditCommandColumn column">
</EditColumn>
</EditFormSettings>
<ItemStyle Font-Names="Eras Medium ITC" Font-Size="X-Small" />
<PagerStyle Mode="NextPrevNumericAndAdvanced" />
<FilterItemStyle Font-Names="Eras Medium ITC" Font-Size="X-Small" />
</MasterTableView>
<EditItemStyle Font-Names="Eras Medium ITC" Font-Size="X-Small" />
<FooterStyle Font-Names="Eras Medium ITC" Font-Size="X-Small" />
<HeaderStyle Font-Names="Eras Medium ITC" Font-Size="X-Small" />
<FilterItemStyle Font-Names="Eras Medium ITC" Font-Size="X-Small" />
<CommandItemStyle Font-Names="Eras Medium ITC" Font-Size="X-Small" />
<ActiveItemStyle Font-Names="Eras Medium ITC" Font-Size="X-Small" />
<ItemStyle Font-Names="Eras Medium ITC" Font-Size="X-Small" />
<PagerStyle Font-Names="Eras Medium ITC" Font-Size="X-Small"
HorizontalAlign="Left" Mode="NextPrevNumericAndAdvanced" />
<SelectedItemStyle Font-Names="Eras Medium ITC" Font-Size="X-Small" />
<FilterMenu Font-Names="Eras Medium ITC" Font-Size="X-Small"
EnableRoundedCorners="True">
</FilterMenu>
<HeaderContextMenu Font-Names="Eras Medium ITC" Font-Size="X-Small"
Skin="Simple">
</HeaderContextMenu>
</telerik:RadGrid>
后面的代码:
public void setSqlDatSource()
{
gridSearchL3.DataSource = getsource();
}
public DataTable getsource()
{
string Query;
Query = @"select distinct h.DocumentNumber 'Document Number' " +
" from tblDocumentHeader h where h.DocumentHeaderTypeID=3 ";
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["PinCBusMgtDocs.Properties.Settings.PINCConnectionString"].ConnectionString);
DataTable dt = new DataTable();
using (SqlDataAdapter da = new SqlDataAdapter(Query, con))
{
da.Fill(dt);
}
return dt;
}
protected void RadGrid1_NeedDataSource(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
{
setSqlDatSource();
}
protected void gridSearchL3_ColumnCreated1(object sender, GridColumnCreatedEventArgs e)
{
if (e.Column.UniqueName == "Document Number")
{
e.Column.FilterControlWidth = 120;
e.Column.HeaderStyle.Width = Unit.Pixel(120);
e.Column.AutoPostBackOnFilter = true;
e.Column.CurrentFilterFunction = GridKnownFunction.Contains;
}
}
}