Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Eval not working with comparison

Tags:

c#

.net

asp.net

In the following textbox, the text is populated with Minutely.

<telerik:RadTextBox ID="RadTextBox1" Runat="server" Text='<%# Eval("FREQUENCY") %>' />

I am trying select a combobox item based on the prexisting frequency. This code gives me a object not set to an instance of an object error:

<telerik:RadComboBoxItem runat="server" Text="One Time Run" Value="OneTimeRun" Selected='<%# (Eval("FREQUENCY").ToString() == "OneTimeRun" ? true : false) %>' />

I have tried the following ways to no success:

<telerik:RadComboBoxItem runat="server" Text="One Time Run" Value="OneTimeRun" Selected='<%# (Eval("FREQUENCY").ToString() == "OneTimeRun") %>' />
<telerik:RadComboBoxItem runat="server" Text="One Time Run" Value="OneTimeRun" Selected='<%# Eval("FREQUENCY").ToString() == "OneTimeRun" ? true : false %>' />

I don't understand what is wrong. If my textbox is being populated with the text "Minutely", why am I getting this error when I want to do comparison.

like image 937
Justin Avatar asked Aug 06 '26 17:08

Justin


1 Answers

I guess you just can't use Eval on combo item since there's no datasource bound to it.

I suggest instead of trying to set Selected on your combo item, you should do the following: create a datasource of your items, bind the combo to the collection, set SelectedValue of the combo declaratively using Eval as you do now.

like image 140
Wiktor Zychla Avatar answered Aug 08 '26 09:08

Wiktor Zychla



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!