0

Hi I have a child componenet positiongrid and I want to invoike this coponent on button click inside parent compoenet

Parent Compoenent Code below

 <div class="form-group col-md-3">
        <button class="btn btn-primary" @onclick="DisplayPositionRefGrid">
          Create
        </button>
    </div>
</div>


   <div class="form-row" id="divPositionRefGrid" hidden="@HideGrid">
       <div class="form-group col-md-12">
           <PositionRefGrid>

           </PositionRefGrid>

          
       </div>
   </div>

The issue is that the child component loading at the same time when the parent is loading but I want to load the child component on button click method 'DisplayPositionRefGrid'

1 Answer 1

2

Use Boolean variable to conditionally display the child component.

<div class="form-group col-md-3">
        <button class="btn btn-primary" @onclick="DisplayPositionRefGrid">
          Create
        </button>
    </div>


@if (ShowGrid )
{
   <div class="form-row" id="divPositionRefGrid" hidden="@HideGrid">
       <div class="form-group col-md-12">
           <PositionRefGrid>

           </PositionRefGrid>

          
       </div>
   </div>
}

@code{

private bool ShowGrid {get;set;}

void DisplayPositionRefGrid()
{
  ShowGrid =true;

//other stuf
//...
}
}

Try it online

Sign up to request clarification or add additional context in comments.

6 Comments

I donot show /Hid ethe grid . I want to load the grid on button click as the grid will take some paramter from the parent compoennet and then when create button clicked the grid will dis[play
Pass the parameters of the grid from the parent in the html code (if it have Parameter in the child component) e.g <PositionRefGrid data="employee" Display="wide">
I want to restrict the gridview rows by slecting it from parent.That is hwy I want to create the grid on button click.Can you help me on this
What is the package components are you using for GridView?
Thanks a lot M.Hassan .The solution you provided worked for me
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.