MVP RadioButtonList SelectValue invalid - mvp

I have a RadioButtonList with 2 listitems. The value of the two list items is true and false.
I've a boolean value called Daily. Daily is set to 'false'
Here's the code snippet:
<asp:RadioButtonList runat="server" ID="pfRadioButtonList" SelectedValue="<%# Model.Daily.ToString() %>" AutoPostBack="True" OnSelectedIndexChanged="PFRadioButtonList_OnSelectedIndexChanged">
<asp:ListItem Text="Item 1" Value="false"></asp:ListItem>
<asp:ListItem Text="Item 2" Value="true"></asp:ListItem>
</asp:RadioButtonList>
The problem is on running I get the follwing error:
'pfRadioButtonList' has a selectedvalue which is invalid because it does not exist in the list of items.
Any suggestions anyone please?!

Booleans in C# output their values with capital letters, so
bool f = false;
Console.Write(f.ToString());
outputs False, not false. Try reflecting that in your markup:
<asp:ListItem Text="Item 1" Value="False"></asp:ListItem>
<asp:ListItem Text="Item 2" Value="True"></asp:ListItem>

Related

Radzen DataGrid Multiple Selection only filtered Items

I have a Razor Component (.net 6) where I make use of the Radzen DataGrid Multiple Selection.
<RadzenDataGrid
#ref="contactsGrid" Data="#contacts" AllowColumnResize="true" EditMode="DataGridEditMode.Single"
RowUpdate="#OnUpdateRow" RowCreate="#OnCreateRow"
AllowSorting="true" AllowFiltering="true" FilterCaseSensitivity="FilterCaseSensitivity.CaseInsensitive"
TItem="ContactModel" AllowRowSelectOnRowClick="false" SelectionMode="DataGridSelectionMode.Multiple" #bind-Value=#selectedContacts>
<Columns>
<RadzenDataGridColumn TItem="ContactModel" Width="40px" Sortable="false" Filterable="false">
<HeaderTemplate>
<RadzenCheckBox TriState="false" TValue="bool" Value="#(contacts.Any(i => selectedContacts != null && selectedContacts.Contains(i)))" Change="#(args => selectedContacts = args ? contacts.ToList() : null)" />
</HeaderTemplate>
<Template Context="contacts">
<RadzenCheckBox TriState="false" Value="#(selectedContacts != null && selectedContacts.Contains(contacts))" TValue="bool" Change=#(args => { contactsGrid.SelectRow(contacts); }) />
</Template>
</RadzenDataGridColumn>
<!-- FirstName -->
<RadzenDataGridColumn TItem="ContactModel" Property="FirstName" Title="FirstName">
<EditTemplate Context="contact">
<RadzenTextBox #bind-Value="contact.FirstName" Style="width:100%; display: block" Name="FirstName" />
<RadzenRequiredValidator Text="FirstName is required" Component="FirstName" Popup="true" />
</EditTemplate>
</RadzenDataGridColumn>
<!-- LastName -->
<RadzenDataGridColumn TItem="ContactModel" Property="LastName" Title="LastName">
<EditTemplate Context="contact">
<RadzenTextBox #bind-Value="contact.LastName" Style="width:100%; display: block" Name="LastName" />
<RadzenRequiredValidator Text="LastName is required" Component="LastName" Popup="true" />
</EditTemplate>
</RadzenDataGridColumn>
</Columns>
</RadzenDataGrid>
In the HeaderTemplate you can directly select or deselect all items.
Is it possible to change the function so that only all items are selected that match the filter? i.e. which items are currently displayed when I search for certain items using the filter option?
you can use contactsGrid.View to get visible rows. try to use contactsGrid.View instead of selectedContacts.

How Can I get Cell Values from Telerik RadGrid

I am having a problem getting the values from the Radgrid auto generated Insert form.
I have my radgrid setup as shown in code shown below. I am only doing inserts and deletes and am using the edit form that is automatically opened when I click the add new record button.
<div id ="specialrequestGrid" class="container">
<div class="row">
<div class="col-md-12">
<telerik:RadAjaxPanel runat="server">
<telerik:RadGrid ID="SpecialRequests" runat="server" OnInsertCommand="SpecialRequests_InsertCommand"
OnUpdateCommand="SpecialRequests_UpdateCommand"
OnItemCommand="SpecialRequests_ItemCommand"
AllowAutomaticInserts="false"
AutoGenerateColumns="false"
OnNeedDataSource="SpecialRequests_NeedDataSource">
<MasterTableView CommandItemDisplay="Top" DataKeyNames="CaseId_FK, ReqId" Font-Size="Medium" NoMasterRecordsText="No Special Requests">
<CommandItemSettings AddNewRecordImageUrl="../Images/Add.png" />
<Columns>
<telerik:GridTemplateColumn HeaderText="Request Date" UniqueName="DateTemplateColumn">
<ItemTemplate>
<asp:Label ID="DateEditItemTemplate" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "Date","{0:MM/dd/yyyy}") %>'>
</asp:Label>
</ItemTemplate>
<EditItemTemplate>
<telerik:RadDatePicker ID="dpRideDate" runat="server" DateInput-DateFormat="MM/dd/yyyy" DbSelectedDate='<%# Bind("Date") %>' MinDate="1999/1/1" UniqueName="dpRideDate">
</telerik:RadDatePicker>
</EditItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridTemplateColumn HeaderText="Requested By ID" UniqueName="RequestorTemplateColumn">
<ItemTemplate>
<asp:Label ID="Requestor" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "RequesterEID_FK") %>'>
</asp:Label>
</ItemTemplate>
<EditItemTemplate>
<button id="btnRequestEID" type="button" class="btn" data-toggle="modal" data-target="#myModal" >--Please Select--</button>
<div>
<input type="text" Id="TxtSPRequestName" disabled />
</div>
</EditItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridTemplateColumn HeaderText="Request Reason" UniqueName="RequestReason">
<ItemTemplate>
<asp:Label ID="ItemTemplatelblRequestReason" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "Reason") %>'>
</asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:Label ID="lblRequestReason" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "Reason") %>' Visible="false">
</asp:Label>
<asp:TextBox runat="server" ID="txtReason" Text='<%# DataBinder.Eval(Container.DataItem, "Reason") %>'></asp:TextBox>
</EditItemTemplate>
</telerik:GridTemplateColumn>
<telerik:GridCheckBoxColumn DataField="IsWOO" HeaderText="Is Out of Order" UniqueName="ISWOO"></telerik:GridCheckBoxColumn>
</Columns>
</MasterTableView>
</telerik:RadGrid>
</telerik:RadAjaxPanel>
</div>
</div>
</div>
This is the screenshot of the auto generated form I get when I click the add new record
When I click the Insert link on the form I run this C# code
protected void SpecialRequests_InsertCommand(object sender, GridCommandEventArgs e)
{
GridEditableItem editedItem = e.Item as GridEditableItem;
UserControl userControl = (UserControl)e.Item.FindControl(GridEditFormItem.EditFormUserControlID);
T_SpecialRequests t = new T_SpecialRequests();
t.IsWOO = (userControl.FindControl("IsWOO") as CheckBox).Checked;
}
Note the IsWOO is a control in the Radgrid that I did not show in the Screenshot. When I click the save link the Insert Function, shown above Runs but I get the following error:
Unhandled exception at line 1, column 123034 in http://localhost:52028/bundles/MsAjaxJs?v=c42ygB2U07n37m_Sfa8ZbLGVu4Rr2gsBo7MvUEnJeZ81
0x800a139e - JavaScript runtime error: Sys.WebForms.PageRequestManagerServerErrorException: Object reference not set to an instance of an object.
The strange part is I use this same code in several other projects without any problems. The only difference is this is the first time I have used this auto generated form. I don't want to use the another type of control for this Radgrid due to such a small number of fields, only have 4 control.
I have spent several hours searching for an answer but just can't find the solution.
How can I get the values from this auto generated form?
You can use
t.IsWOO = (editedItem["ISWOO"].Controls[0] as CheckBox).Checked;
or
var newValues = new Dictionary<string, object>();
e.Item.OwnerTableView.ExtractValuesFromItem(newValues, editedItem);
t.IsWOO = (bool)newValues["IsWOO"];
The first approach references the control by index because unfortunately it has no ID.
The second one is a bit verbose for just one property but I would surely prefer it if there were more properties.
While #Michal Nawrocik was correct I found that I still had some problems reading all of the controls in the Radgrid. I was able to track down the answer on the Telerik forum and found that you have to use different code based on the Column Type. I had 2 different type of columns.
the code below shows what I used to get all of the control values on the form
protected void SpecialRequests_InsertCommand(object sender, GridCommandEventArgs e)
{
try
{
using(LatentEntities db = new LatentEntities())
{
if (e.Item is GridEditableItem)
{
T_SpecialRequests T = new T_SpecialRequests();
var editableItem = ((GridEditableItem)e.Item);
RadDatePicker picker = (RadDatePicker)editableItem.FindControl("dpDate"); // in EditItem Template
DateTime dt = Convert.ToDateTime(picker.DbSelectedDate);
T.Date = dt;
TextBox Reason = (TextBox)editableItem.FindControl("txtReason"); //This Control was in an Edit Item Template
T.Reason = Reason.Text;
T.IsWOO = (editableItem["ISWOO"].Controls[0] as CheckBox).Checked; //In CheckBox Column
}
}
And if the control is in a Telerik:GridtboundColumn I used this code:
string strFirstName = (editableItem["firstname"].Controls[0] as TextBox).Text;

Query on Radtabstrip an radmultipage

I have use Radtapstrip with six tabs.
i have mandatory fields on first tab with validation. if i click button with first tab validation is working fine.when i click 2,3,4,5 and 6th tab validation does not working. i need render to first tab if i have not filled mandatory fields on first tab. please guide me. Thanks.
<telerik:RadTabStrip ID="radtabData" runat="server" ClickSelectedTab="true" TabIndex="0" MultiPageID="radMultiPage2" SelectedIndex="0" ShowBaseLine="True" EnableEmbeddedSkins="False" Skin="Sunset" >
<Tabs>
<telerik:RadTab PageViewID="pvTab1" TabIndex="0" Text="Client Information" Value="ClientInformation" SelectedCssClass="rtsDisabled" >
</telerik:RadTab>
<telerik:RadTab PageViewID="pvTab2" TabIndex="1" Text="Pre Clinical Exam" Value="PreClinicalExam"></telerik:RadTab>
<telerik:RadTab PageViewID="pvTab3" TabIndex="2" Text="Procedure" Value="Procedure">
</telerik:RadTab>
<telerik:RadTab PageViewID="pvTab4" TabIndex="3" Text="Client Medical History" Value="ClientMedicalHistory"></telerik:RadTab>
<telerik:RadTab PageViewID="pvTab5" TabIndex="4" Text="Post Clinical Exam" Value="PostClinicalExam"></telerik:RadTab>
<telerik:RadTab PageViewID="pvTab6" TabIndex="5" Text="Custom" Value="Custom">
</telerik:RadTab>
</Tabs>
</telerik:RadTabStrip>
<telerik:RadMultiPage ID="radMultiPage2" runat="server" CssClass="MultipageWrapper" SelectedIndex="0" Style="width: 1000px;" BorderColor="Gray" BorderWidth="1px">
<telerik:RadPageView ID="pvTab1" runat="Server">
.
.
</telerik:Radpageview>
<telerik:RadPageView ID="pvTab2" runat="Server">
.
.
</telerik:Radpageview>
<telerik:RadPageView ID="pvTab3" runat="Server">
.
.
</telerik:Radpageview>
<telerik:RadPageView ID="pvTab4" runat="Server">
.
.
</telerik:Radpageview>
<telerik:RadPageView ID="pvTab5" runat="Server">
.
.
</telerik:Radpageview>
<telerik:RadPageView ID="pvTab6" runat="Server">
.
.
</telerik:Radpageview>
</telerik:RadMultiPage>
One method I can come up with is to validate the page on load, if the page is not valid you could then programmatically set the telerik:RadMultiPage element to display the
public void Page_Load(object sender, EventArgs e)
{
Validate("myValidationGroupName");
if ((Page.IsValid)) {
RadTabStrip.Tabs[i].Selected = true
radMultiPage2.PageViews[0].Selected = true;
}
}
You will also probably want to set the telerik:RadTabStrip to validate before submitting preventing the page from being navigated from before the required/validated fields are populated/validated.
<telerik:RadTabStrip ... CausesValidation="true" ValidationGroup="myValidationGroupName">
In the code examples used I have used a ValidationGroup, I have done this as it is possible that you have other "Validation Groups" on the page which you do not want preventing navigation from the first page.

Telerik RadCombobox SelectedIndexedChange Event

I have a telerik:RadCombobox in which user can type something to filter the recoreds.
If user type some word and tabout from taht control or clicked anywhere else on the form, basically onblur , its selectedindexedchanged event is fired that I don't want.
Please advise.
I have following html code on my page:
<telerik:RadComboBox ID="RCBGlobalSearch" runat="server" Height="190px" Width="330px"
EnableLoadOnDemand="true" ShowMoreResultsBox="true" EnableVirtualScrolling="true"
OnClientDropDownClosed="OnClientDropDownClosed" MarkFirstMatch="false" Filter="None"
HighlightTemplatedItems="true" Style="z-index: 9000" OnSelectedIndexChanged="RCBGlobalSearch_SelectedIndexChanged"
AutoPostBack="true" ToolTip="Enter or Select Issuer or User for Search">
<ExpandAnimation Type="none" />
<CollapseAnimation Type="none" />
<WebServiceSettings Path="~\GlobalSearchWebService.asmx" Method="GetGlobalSearchResult" />
</telerik:RadComboBox>
http://www.telerik.com/help/aspnet-ajax/combobox-onclienttextchange.html
- set_cancel lets you prevent the combobox from doing a postback (if AutoPostBack property is True), but doesn't let you prevent the text from changing.
<script language="javascript" type="text/javascript">
function OnClientTextChange(sender, eventArgs) {
eventArgs.set_cancel(true);
}
</script>
<telerik:RadComboBox onclienttextchange="OnClientTextChange"....

how String.Format of RadGrid(Telerik) Sum result in footer?

my radgrid column like below :
<telerik:GridTemplateColumn FilterControlAltText="Filter TemplateColumn_Benefit" DataField="Benefit"
HeaderText="Benefit" UniqueName="TemplateColumn_Benefit" FilterImageToolTip="Filter">
<ItemTemplate>
<asp:Label ID="lblBenefitInsideGrd" runat="server" Font-Size="11px" Text='<%# (bool)Convert.IsDBNull(Eval("Benefit")) ? "<span class=\"lblInsideGrd\">Empty</span>" : String.Format("{0:#,0 Dollar;#,0- Dollar}", Eval("Benefit")) %>'></asp:Label>
</ItemTemplate>
<HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle" Width="60px" />
<ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" Width="60px" />
</telerik:GridTemplateColumn>
how can i String.Format(reformat) Sum result in footer for this template column ?
mean i want something like {0:#,0 Dollar;#,0- Dollar} in output...
thanks in advance
the below link solved my problem :
http://demos.telerik.com/aspnet-ajax/grid/examples/generalfeatures/aggregates/defaultcs.aspx
/// <summary>
/// The MasterTableView.DataBinding event is used to preserve the applied formatting to
/// data values in the column aggregate and still be able to add the name of the currently
/// selected aggregate function.
/// </summary>
protected void MasterTableView_DataBinding(object sender, EventArgs e)
{
GridNumericColumn unitPriceCol = RadGrid1.MasterTableView.GetColumnSafe("UnitPrice") as GridNumericColumn;
unitPriceCol.FooterAggregateFormatString = unitPriceCol.Aggregate.ToString() + ": {0:C}";
}
You can add an additional Format argument to the Eval function:
Eval("Benefit", "{0:#,0 Dollar;#,0- Dollar}")

Resources