Object sender and take text

1

I have 3 different buttons but I want that when clicking on any of them, the text that this brings is saved in a variable by means of the object sender

One of the buttons would be, for example, the following:

<asp:Button ID="Btn_eng" class="btn btn-primary" runat="server" Text="ENG" OnClientClick="showAndHide();" Width="185px" OnClick="Unnamed1_Click"></asp:Button>

and this is the event that occurs when you click:

protected void Unnamed1_Click(object sender, EventArgs e)
    {
        Button Btn_clic = (Button)sender;
        var name = Btn_clic;

        List.ListUsers listArea = new List.ListUsers();
        List<Data.Area> Area = listArea.AreaList();

        List<Data.Area> ListOfEquiposFCHOk = Area.Where(x => x.AREA = name && x.STANDBY == 0).ToList();

        List<Button> Botones = new List<Button>();

        var TeamFCH = ListOfEquiposFCHOk.Select(x => x.TEAM).Distinct().ToList();

        foreach (var team in TeamFCH)
        {
            Button newButton = new Button();
            newButton.Text = team;
            Botones.Add(newButton);
        }

        Panel1.Controls.Add(Botones[0]);
    }

I already managed to save it in the name variable but when I wanted to concatenate it to the linq query it would not accept it, and it would throw the red line under it.

  

Error 150 Operator '& &' can not be applied to operands of type   'System.Web.UI.WebControls.Button' and 'bool'

    
asked by Cesar Gutierrez Davalos 28.06.2017 в 14:55
source

1 answer

3

I imagine that your problem is here:

List<Data.Area> ListOfEquiposFCHOk = Area.Where(x => x.AREA = name && x.STANDBY == 0).ToList();

In the first part of your && clause you have put an assignment operator = instead of one comparison%% co_:

List<Data.Area> ListOfEquiposFCHOk = Area.Where(x => x.AREA == name && x.STANDBY == 0).ToList();

On the other hand, I think that in this line == what you want to save is the id of the button or its text, not the button itself, so I think it should be:

var name = Btn_clic.ID;

or

var name = Btn_clic.Text;
    
answered by 28.06.2017 / 15:25
source