Datagrid - template with checkbox - bind to variable?

When I try binding a checkbox within a template for a datagrid column - Property is 'Ignore' - and it seems to expect a variable to be used for @bind-Value, but I'm using an IEnumerable for the data source so I try to use a lambda expression as the @bind-Value but then I get compile errors. Am I approaching this wrong?

Cannot convert lambda expression to intended delegate type because some of the return types in the block are not implicitly convertible to the delegate return type
The left-hand side of an assignment must be a variable, property or indexer

<RadzenGrid Count="@AgentSurveyReviews.Count()" Data="@AgentSurveyReviews" TItem="@AgentSurveyReviewModel" ColumnWidth="200px" Visible="true" AllowSorting="true"
                AllowFiltering="true" AllowPaging="true" PageSize="50" ExpandMode="DataGridExpandMode.Multiple" Style="height: 560px; width: 1230px">
    <Template Context="AgentSurveyReviews">
       <RadzenCard Style="margin-left: 50px">
           Login ID:
           @AgentSurveyReviews.LoginId
           <RadzenGrid TItem="@AgentSurveyReviewModel">
               <Columns>
                  <RadzenGridColumn TItem="@AgentSurveyReviewModel" Property="Id" Title="Id" Visible="true" Width="80px"></RadzenGridColumn>
                  <RadzenGridColumn TItem="@AgentSurveyReviewModel" Property="TimeStampFirstSegment" Title="First Segment" Visible="@AgentSurveyPreference.TimestampFirstSegment" Width="180px"></RadzenGridColumn>
               </Columns>
           </RadzenGrid>
        </RadzenCard>
     </Template>
     <Columns>
        <RadzenGridColumn TItem="@AgentSurveyReviewModel" Property="Id" Title="Id" Visible="true" Width="80px"></RadzenGridColumn>
        <RadzenGridColumn TItem="@AgentSurveyReviewModel" Property="Ignore" Title="Ignore" Visible="@AgentSurveyPreference.Invalid" Width="80px" Type="boolean">
             <Template>
                  <RadzenCheckBox TValue="bool" @bind-Value="@AgentSurveyReviews.Select(i => i.Ignore).FirstOrDefault()" Change="@(args => UpdateIgnoreRadzen(AgentSurveyReviews.Select(i => i.Ignore).FirstOrDefault(), AgentSurveyReviews.Select(i => i.Id).FirstOrDefault()))"></RadzenCheckBox>
             </Template>
        </RadzenGridColumn>
      </Columns>
</RadzenGrid>
1 Like

You cannot use two-way binding with such expression - you need to provide property. I strongly suggest you to check Blazor documentation for more info about bindings.

Ok. I changed the IEnumerable to a List and if I do something like this I'm able to get to the property - now the issue is figuring out how to get it to refer to the correct index on each row (i.e. not hard code it - which also may be more about learning how to use Blazor than the Radzen grid):



<RadzenCheckBox TValue="bool" @bind-Value="@AgentSurveyReviews[0].Ignore" Change="@(args => UpdateIgnoreRadzen.Ignore, AgentSurveyReviews.Select(i => i.Id).FirstOrDefault()))">


I'm trying to do something similar, albeit with a template and context to display the checkboxes and flip the value but not having any luck as I can't bind a template's context to the checkbox... Not sure if I should make a new topic since its so similar.


<RadzenCheckBox TValue="bool" @bind-Value="CRevent.IsOnDNCList" >

looks like my code snippet isn't showing correctly >.<

Mine is also within a template.

<code>
        <RadzenGridColumn TItem="@AgentSurveyReviewModel" Property="Ignore" Title="Ignore" Visible="@AgentSurveyPreference.Invalid" Width="80px" Type="bool">
            <Template>
                <RadzenCheckBox TValue="bool" @bind-Value="@AgentSurveyReviews[0].Ignore" Change="@(args => UpdateIgnoreRadzen(AgentSurveyReviews.Select(i => i.Ignore).FirstOrDefault(), AgentSurveyReviews.Select(i => i.Id).FirstOrDefault()))"></RadzenCheckBox>
            </Template>
        </RadzenGridColumn>
</code>

Ok, so I suppose we are trying to accomplish something similar then
Let me try to post this code again... the template with context, under the datagrid column declaration

<RadzenGridColumn TItem="CalendarRulesEvent" Property="IsOnDNCList" 
   Title="Save?" Type="boolean" >
   <Template context="CRevent">
      <RadzenCheckBox TValue="bool" 
           @bind-Value="CRevent.IsOnDNCList">
      </RadzenCheckBox>
   </Template>
</RadzenGridColumn>
1 Like

That was it, I was missing the context. I put the data source back to an IEnumberable and this is working - and I was able to use properties for the parameters I'm passing in the change event:

<RadzenGridColumn TItem="@AgentSurveyReviewModel" Property="Ignore" Title="Ignore" Visible="@AgentSurveyPreference.Invalid" Width="80px" Type="bool">
  <Template Context="AgentSurveyReviews">
    <RadzenCheckBox TValue="bool" 
       @bind-Value="@AgentSurveyReviews.Ignore" 
       Change="@(args => UpdateIgnoreRadzen(AgentSurveyReviews.Ignore, AgentSurveyReviews.Id))"><RadzeenCheckBox>
  </Template>
</RadzenGridColumn>

Thank you!

Hey no problem, glad that turned out to be the missing piece!