Getting a row table pointer using LINQ

You need to get the row index in LINQ, then use this value to indicate my DropDownList.SelectedIndex when the page loads or postback.

    public String GetRoleName(Int16 RoleID)
    {
        SQL_TA_SCOREBOARDEntities1 c = new SQL_TA_SCOREBOARDEntities1();

        String qry = (from b in c.EmployeeAccessLevels
                      where b.id == RoleID
                      select b.Role).FirstOrDefault();

        return qry;
    }

I take the role name for the dropdown to display, but that still doesn't work.

            String RoleName = MyClass.RoleName(RoleID);
            ddlRole.Text = RoleName

So, I really need an index.

Thanks in advance!

+4
source share
1 answer

I don't think getting a row index directly is possible in LINQ.

You can just try

    ddlRole.Items[0].Text = RoleName
+2
source

Source: https://habr.com/ru/post/1534749/


All Articles