I'm getting this error "No property or field 'PhoneNumber' exists in type 'DataRowView'" when I try to rebind my grid after changing the filterexpression.
I hope someone can explain why.
My c# code is:
The markup for the grid is:
I hope someone can explain why.
My c# code is:
protected void btnFilter_Click(object sender, EventArgs e) |
{ |
string filter = ""; |
switch (cboFilter.SelectedValue) |
{ |
case "AccountNumber": |
{ |
filter = String.Format("(AccountNumber LIKE '%{0}%')", txtFilter.Text.Trim()); |
break; |
} |
case "DateRange": |
{ |
if ((rdpDateFrom.SelectedDate != null) && (rdpDateTo.SelectedDate != null)) |
{ |
filter = String.Format("(DateFrom >= {0}) AND (DateTo <= {1})", rdpDateFrom.SelectedDate, rdpDateTo.SelectedDate); |
} |
else if ((rdpDateFrom.SelectedDate != null) && (rdpDateTo.SelectedDate == null)) |
{ |
filter = String.Format("(DateFrom >= {0})", rdpDateFrom.SelectedDate); |
} |
else if ((rdpDateFrom.SelectedDate == null) && (rdpDateTo.SelectedDate != null)) |
{ |
filter = String.Format("(DateTo <= {0})", rdpDateTo.SelectedDate); |
} |
break; |
} |
case "FullName": |
{ |
filter = String.Format("(FullName LIKE '%{0}%')", txtFilter.Text.Trim()); |
break; |
} |
case "PhoneNumber": |
{ |
filter = String.Format("(PhoneNumber LIKE '%{0}%')", txtFilter.Text.Trim()); |
break; |
} |
} |
rgBills.MasterTableView.FilterExpression = filter; |
rgBills.MasterTableView.DataBind(); |
} |
The markup for the grid is:
<telerik:RadGrid ID="rgBills" runat="server" Skin="Web20" |
AllowPaging="True" AllowSorting="True" GridLines="None" DataSourceID="dsBills" |
OnItemDataBound="rgBills_ItemDataBound" OnItemCommand="rgBills_ItemCommand" |
ShowFooter="True" OnSelectedIndexChanged="rgBills_SelectedIndexChanged" > |
<HeaderContextMenu EnableTheming="True"> |
<CollapseAnimation Type="OutQuint" Duration="200"></CollapseAnimation> |
</HeaderContextMenu> |
<ClientSettings> |
<Selecting AllowRowSelect="true" /> |
</ClientSettings> |
<FilterItemStyle Width="90%" /> |
<MasterTableView AutoGenerateColumns="False" DataSourceID="dsBills" DataKeyNames="AutoNumber"> |
<RowIndicatorColumn> |
<HeaderStyle Width="20px"></HeaderStyle> |
</RowIndicatorColumn> |
<ExpandCollapseColumn> |
<HeaderStyle Width="20px"></HeaderStyle> |
</ExpandCollapseColumn> |
<Columns> |
<telerik:GridTemplateColumn AllowFiltering="false"> |
<HeaderTemplate> |
<asp:CheckBox runat="server" ID="CheckBoxHeader" OnCheckedChanged="ToggleSelectedState" |
AutoPostBack="true" /> |
</HeaderTemplate> |
<ItemTemplate> |
<asp:CheckBox runat="server" ID="CheckBox1" OnCheckedChanged="ToggleRowSelection" |
AutoPostBack="true" /> |
</ItemTemplate> |
</telerik:GridTemplateColumn> |
<telerik:GridBoundColumn DataField="PhoneNumber" HeaderText="Phone Number" ReadOnly="True" |
SortExpression="PhoneNumber" UniqueName="PhoneNumber"> |
</telerik:GridBoundColumn> |
<telerik:GridTemplateColumn DataField="FullName" HeaderText="Full Name" SortExpression="FullName" |
UniqueName="FullName"> |
<ItemTemplate> |
<asp:LinkButton ID="lnkUserAccount" runat="server" Text='<%# Bind("FullName") %>' |
OnClick="lnkUserAccount_Click" /></ItemTemplate> |
</telerik:GridTemplateColumn> |
<telerik:GridBoundColumn DataField="AccountNumber" HeaderText="Account Number" SortExpression="AccountNumber" |
UniqueName="AccountNumber" DataType="System.String"> |
</telerik:GridBoundColumn> |
<telerik:GridBoundColumn DataField="Email" HeaderText="Email" SortExpression="Email" |
UniqueName="Email" Display="false"> |
</telerik:GridBoundColumn> |
<telerik:GridBoundColumn DataField="AutoNumber" DataType="System.Int64" HeaderText="AutoNumber" |
ReadOnly="True" SortExpression="AutoNumber" UniqueName="AutoNumber" Display="false"> |
</telerik:GridBoundColumn> |
<telerik:GridBoundColumn DataField="UserName" HeaderText="UserName" SortExpression="UserName" |
UniqueName="UserName" Display="false"> |
</telerik:GridBoundColumn> |
<telerik:GridDateTimeColumn DataField="DateFrom" DataType="System.DateTime" HeaderText="Date From" |
SortExpression="DateFrom" UniqueName="DateFrom" DataFormatString="{0:dd/MM/yyyy}" |
FilterControlWidth="100px"> |
<ItemStyle HorizontalAlign="Center" /> |
<HeaderStyle HorizontalAlign="Center" /> |
</telerik:GridDateTimeColumn> |
<telerik:GridDateTimeColumn DataField="DateTo" DataType="System.DateTime" HeaderText="Date To" |
SortExpression="DateTo" UniqueName="DateTo" DataFormatString="{0:dd/MM/yyyy}" |
FilterControlWidth="100px"> |
<ItemStyle HorizontalAlign="Center" /> |
<HeaderStyle HorizontalAlign="Center" /> |
</telerik:GridDateTimeColumn> |
<telerik:GridTemplateColumn AllowFiltering="false"> |
<ItemTemplate> |
<asp:LinkButton ID="cmdShowDetails" runat="server" CommandName="ShowDetails" Text="Show Details" /></ItemTemplate> |
</telerik:GridTemplateColumn> |
</Columns> |
<PagerStyle Mode="NextPrevNumericAndAdvanced" /> |
</MasterTableView> |
<ClientSettings> |
<Selecting AllowRowSelect="True" /> |
</ClientSettings> |
<FilterMenu EnableTheming="True"> |
<CollapseAnimation Type="OutQuint" Duration="200"></CollapseAnimation> |
</FilterMenu> |
<EditItemStyle BackColor="#5174AA" /> |
</telerik:RadGrid> |